fork():
The fork() system call will spawn a new child process which
is an identical process to the parent except that has a new
system process ID. The process is copied in memory from the parent and a new
process structure is assigned by the kernel. The return value of the
function is which discriminates the two threads of execution. A zero is
returned by the fork function in the child's process.
The environment, resource limits, umask, controlling terminal, current working
directory, root directory, signal masks and other process resources are also
duplicated from the parent in the forked child process.
#include <iostream>
08 | #include <stdlib.h> // Declaration for exit() |
12 | int globalVariable = 2; |
17 | int iStackVariable = 20; |
24 | sIdentifier = "Child Process: " ; |
30 | cerr << "Failed to fork" << endl; |
38 | sIdentifier = "Parent Process:" ; |
44 | cout << " Global variable: " << globalVariable; |
45 | cout << " Stack variable: " << iStackVariable << endl; |
No comments:
Post a Comment