Systems Programming - Systems Programming - Quiz, Exercises of System Programming

Main points of this documents are: Systems, Programming, Compiled, Run, Zombie, Processes, System, Calls, Fork, Excel.

Typology: Exercises

2011/2012

Uploaded on 10/24/2012

gaggan
gaggan 🇮🇳

4.4

(51)

111 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Systems Programming
Assignment #1
Q1: When the following program is compiled and run,
File : funny.cpp
| /*
| A very funny program ...
| */
| #include <iostream>
+ #include <sys/types.h>
| #include <unistd.h>
| using namespace std;
| int
| main( ) {
10 fork( ); cout << "hee " << endl;
| fork( ); cout << "ha " << endl;
| fork( ); cout << "ho " << endl;
| return 0;
| }
assuming all fork system calls are successful, how many lines of output will be
produced? Is it ever possible for a ho to be output before a hee? Why is this? Would the
number of hees, has and hos be different if the << endl was left out of each of the cout
statements? Why?
Q2: Write a program that produces three zombie processes. Submit evidence, via the
output of the ps command, that these processes are truly generated and are eventually
destroyed.
Q3: A program which creates its child by fork system call. The task of parent is to
print alphabets from a to j (using for loop), and the task of child is to print decimal
numbers from 0 to 9. You have to write this program which using wait system call
in such a way that results of parent and child could not be jumble up.
Q4: Prove that Process ID of parent and it’s child created through exec system
calls is same.
Q5: A process creates it’s child through the fork system call. The child created by
fork creates another process through execl system call. Prove that the Process ID
of process created by fork and through execl is same.
Docsity.com

Partial preview of the text

Download Systems Programming - Systems Programming - Quiz and more Exercises System Programming in PDF only on Docsity!

Systems Programming

Assignment

Q1: When the following program is compiled and run,

File : funny.cpp | /* | A very funny program ... | */ | #include

  • #include <sys/types.h> | #include <unistd.h> | using namespace std; | int | main( ) { 10 fork( ); cout << "hee " << endl; | fork( ); cout << "ha " << endl; | fork( ); cout << "ho " << endl; | return 0; | }

assuming all fork system calls are successful, how many lines of output will be

produced? Is it ever possible for a ho to be output before a hee? Why is this? Would the

number of hees, has and hos be different if the << endl was left out of each of the cout

statements? Why?

Q2: Write a program that produces three zombie processes. Submit evidence, via the

output of the ps command, that these processes are truly generated and are eventually

destroyed.

Q3: A program which creates its child by fork system call. The task of parent is to

print alphabets from a to j (using for loop), and the task of child is to print decimal

numbers from 0 to 9. You have to write this program which using wait system call

in such a way that results of parent and child could not be jumble up.

Q4: Prove that Process ID of parent and it’s child created through exec system

calls is same.

Q5: A process creates it’s child through the fork system call. The child created by

fork creates another process through execl system call. Prove that the Process ID

of process created by fork and through execl is same.

Docsity.com