COEN 346 - Winter 2009 Programming Assignment 2 Due: February 20, 2009 Objectives The purpose of this assignment is to study some aspects of the organization and behavior of a Unix/Linux system by observing values in kernel data structure and to familiarize you with basic Unix/Linux process creation and termination (using fork and exec) and implementing them in C/C++ programs. Part I For this part, you are required to write a C/C++ program, called Asg2i.cpp or Asg2i.c, which reports the behavior of the Linux kernel. Your program should print the following value on the standard output: Processor type Kernel version Memory status Any three information about the kernel Any three information about a current running process Linux saves all the information regarding the kernel data structure in the directory /proc. You may manually search this directory for the locations of the needed information then pass them to your program through the shell (i.e. in argv[]). Part II The main goal of this part is to allow you to know how to create and terminate processes and what the relation between a parent and child process is. This part is by itself composed of two sub-parts, II-A & II-B. A) For this sub-part, you are required to write a C/C++ program, called Asg2iia.cpp or Asg2iia.c that does the following: 1) Executes as a parent process, which occurs naturally. The parent process must output the following statement: “Parent process is running and about to fork to a child process”. 2) The process (that is the parent process) must then create a child process (using fork()). The child will simply print out to the standard output the following statement: ”I am the child process”. You are NOT allowed to use the exec calls in this part (Part II-A). That is, you must make sure that the child will still run the proper code to perform what it needs to do COEN 346 – Winter 2009 Programming Assignment # 2 Page 1 of 2 without the executions of any of the “exec” calls. You must notice that the child has no choice but to execute the code that it obtained from its parent, yet it has to perform what it is required to do. Your code must hence take care of that. 3) Once the child starts, the parent must wait for the child to die before it continues. Upon the child termination, the parent must output the following statement “Parent acknowledges child termination Parent will terminate now”. The parent will then terminate. For example you should have a result similar to following when you run Asg2iia: Parent process is running and about to fork to a child process I am the child process Parent acknowledges child termination Parent will terminate now B) For this sub-part, you are required to have a program, called Asg2iib.cpp or Asg2iib.c, which is similar to the one you created in Part II-A above, with the following exceptions: 1) You must write a small program, called “outsider.cpp” or “outsider .c” That program will output the following statement: “Outsider program is running. Time now is ” followed by the current time. 2) Now in your Asgiib.cpp (or .c) you will have to execute the parent as in Part II-A, and then fork to a child process. The child process must then execute the code of the Outsider program using the exec system call. 3) The parent must again wait for the child to terminate. Once this occurs, the parent will issue a statement acknowledging that then terminates. For example you should have a result similar to following when you run Asg2iib: Parent process is running and about to fork to a child process Outsider program is running. Time now is Mon Feb 2 01:17:32 EST 2009 Parent acknowledges child termination Parent will terminate now Deliverables: Tar all your source files from PartI and partII into a file called Asg2_Deliverables.tar. Using the online submission system, submit this tar file. You must make sure that your name and ID are clearly indicated in each of the source code files. Once you submit your assignment, you MUST save the returned confirmation from the online submission system. COEN 346 – Winter 2009 Programming Assignment # 2 Page 2 of 2