CSCI 620 process management Project

{`New york Institute of technology
School of Engineering and Technology 
Department of Computer Science 
CSCI-620 Process Management
`}

Project 1

Tasks

In a new Linux virtual machine within VMPlayer:

  1. To obtain process information for the UNIX or Linux system, use the command ps -ael. Use the command man ps to get more information about the ps command. Describe what this command does.
  2. Construct a process tree similar to Figure 1. Look up the Linux command pstree –p and describe what it does. Then type in the command the capture the output. CSCI 620 process management Project Image 1

    Figure 1

  3. Create a process in the background ( such as (date;sleep 10; date) >date.out & ), and run ps –ael and identify the added processes running now.
  4. Verify the job is running by typing the command jobs. Describe what this command does.
  5. Type the following program in a textfile called three_forks.c. Compile it using gcc and then run it in the background.
    1. Describe what the fork() call does.
    2. Including the initial parent process, how many processes are created by the program shown? Verify your answer by running ps –ael.
    3. Kill the processes created in this part one by one and terminate them by the kill command. Show each is killed by running ps –ael.
{`
#include  
#include  

 // Note that fork() returns a pid - it returns a 0 to the child process... int main() 
{ 
 	pid_t mypid, pid; 

 	  	printf("Start: pid = %d\n", getpid()); 

  	/* fork a child process */  	pid = fork();  	if (pid == 0) 
 	 	printf("Child - ");  	else 
 	 	printf("Parent - "); 
  	printf("After 1st fork: pid = %d\n", getpid()); 

 	  	/* fork another child process */ 
 	pid = fork();  	if (pid == 0) 
 	 	printf("Child - ");  	else 
 	 	printf("Parent - "); 
 	printf("After 2nd fork: pid = %d\n", getpid()); 

 	  	/* and fork another */  	pid = fork();  	if (pid == 0)  	 	printf("Child - ");  	else 
 	 	printf("Parent - "); 
 	printf("After 3rd fork: pid = %d\n", getpid()); 

 	  	while (1);  	return; 
} 
`}