ahmad el zein's Profile

About

 
Points: 0

Contact

 
00393287185846 El Zein

Drop files in here
or click to pick manually
ahmad el zein
November 11, 2015 · Public

Exercise 5

Try to figure out what is the output of the following program:

#include
int main (int argc, char ** argv){
int i = 0;
printf ("%d %d\n", getpid(), ++i);
execl (argv[0], argv[0], 0);
printf ("end\n");
return (1);
}

Then compile and run it and see what's going on

ahmad el zein
November 11, 2015 · Public

Operating Systems

Laboratory 5

Learning goals: in this laboratory activity you will learn how to use waitpid and exec system
calls. You will understand how to wait for a specific child and how to excute command in your
own programs.

Exercise 1
Using system calls fork and waitpid write a program that receive a number n from the command
line and do the following:
1. creates n processes
2. the first child created sleep n second, the second child sleep n-1 seconds and so on.....(the
last child sleep 1 second)
3. the parent wait for “all” the child(it waits sequentially starting from the first created to the
last – you have to use waitpid system call)

-----------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------

Exercise 2

Modify the exercise 1 using wait instead waitpid . How many times the parent has to call “wait” ?
Does this program behaves as the previous one? Check it out!
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------

Exercise 3

Run, in background mode, the programs you wrote in the exercises 1 and 2 and using ps command
try to figure out how many zombie process you have.

ahmad el zein
October 20, 2015 · Public