Process Creation
- Parent and children share all resources
- Children share subset of parent’s resources
- Parent and child share no resources
- Parent and children execute concurrently
- Parent waits until children terminate
- Child duplicate of parent
- Child has a program loaded into it
- fork system call creates new process
- exec system call used after a fork to replace the process’ memory space with a new program
Process Creation |
Process Termination
- Output data from child to parent (via wait)
- Process’ resources are deallocated by operating system
- Child has exceeded allocated resources
- Task assigned to child is no longer required
- If parent is exiting
- Some operating systems do not allow child to continue if its parent terminates
- All children terminated - cascading termination
- Some operating systems do not allow child to continue if its parent terminates
Unix Process Creation
-
- →Unix
fork()
creates a process - Creates a new address space
- Copies text, data, & stack into new adress space
- Provides child with access to open files
- →Unix
- →Unix
exec()
allows a child to run a new program - →Unix
wait()
allows a parent to wait for a child to terminate
Note
In Unix, process creation and management uses multiple, fairly simple system calls. This provides extra flexability. If needed, the parent process may contain the code for the child process to run, so that
exec()
is not always needed. The child may also set up inter-process communication with the parent, such as with a pipe before running another program.exec()
The exec() family of functions replaces the current process image with a new process image. It loads the program into the current process space and runs it from the entry point.
It comes under the header file unistd.h (in c language)
fork vs exec
- fork starts a new process which is a copy of the one that calls it, while exec replaces the current process image with another (different) one.
- Both parent and child processes are executed simultaneously in case of fork() while Control never returns to the original program unless there is an exec() error.
Reference :- https://stackoverflow.com/a/1653415/6793146
No comments:
Post a Comment