Fork System Call

Topics: Process, Parent process, Fork Pages: 2 (258 words) Published: August 18, 2013
Exp#2 fork system call
Aim
To create a new child process using fork system call.
Algorithm
1. Declare a variable x to be shared by both child and parent. 2. Create a child process using fork system call.
3. If return value is -1 then
a. Print "Process creation unsuccessful"
b. Terminate using exit system call.
4. If return value is 0 then
a. Print "Child process"
b. Print process id of the child using getpid system call
c. Print value of x
d. Print process id of the parent using getppid system call
5. Otherwise
a. Print "Parent process"
b. Print process id of the parent using getpid system call
c. Print value of x
d. Print process id of the shell using getppid system call.
6. Stop
Result
Thus a child process is created with copy of its parent's address space.

Exp#2 wait system call
Aim
To block a parent process until child completes using wait system call. Algorithm
1. Create a child process using fork system call.
2. If return value is -1 then
a. Print "Process creation unsuccessfull"
3. Terminate using exit system call.
4. If return value is > 0 then
a. Suspend parent process until child completes using wait system call b. Print "Parent starts"
c. Print even numbers from 0–10
d. Print "Parent ends"
5. If return value is 0 then
a. Print "Child starts"
b. Print odd numbers from 0–10
c. Print "Child ends"
6. Stop
Result
Thus using wait system call zombie child processes were avoided
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • An Inspector Calls Essay
  • Essay about One night @ Call Centre
  • Management System Essay
  • Essay on payroll system
  • Computer System Information System Paper
  • Tuning Forks Essay
  • System Essay
  • It Systems Essay

Become a StudyMode Member

Sign Up - It's Free