Process Control
September 18 by Bina
Learning Outcomes
- Apply Makefile and Make utility to obtain excutable image of source code
- Explain realizing concurrency using Unix Process model
- Explain process state model
- Explain creation of a process using unix fork system call
- Discuss the system call API for process creation and control
We will also look into make utility and makefile in today's class.
Below is the outline for today's lecture.
Process: Fundamental unit of work in an operating system and in a realtime system.
A process is a program in execution: an instance of a program execution.
Unit of work individually schedulable by an operating system (OS).
A process includes:
- program counter
- stack
- data section
OS keeps track of all the active processes and allocates system resources to them according to policies devised to meet design performance objectives.
To meet process requirements OS must maintain many data structures efficiently.
The process abstraction is a fundamental OS means for management of concurrent program execution. Example: instances of process co-existing.
Process creation in unix is by means of the system call fork().
OS in response to a fork() call:
- Allocate slot in the process table for new process.
- Assigns unique pid to the new process..
- Makes a copy of the process image, except for the shared memory.
both child and parent are executing the same code following fork()
- Move child process to Ready queue.
- it returns pid of the child to the parent, and a zero value to the child.
All the above are done in the kernel mode in the process context. When the kernel completes these it does one of the following as a part of the dispatcher:
- Stay in the parent process. Control returns to the user mode at the point of the fork call of the parent.
- Transfer control to the child process. The child process begins executing at the same point in the code as the parent, at the return from the fork call.
- Transfer control another process leaving both parent and child in the Ready state.
Parent process create children processes, which, in turn create other processes, forming a tree of processes
Generally, process identified and managed via a process identifier (pid)
Resource sharing
Parent and children share all resources
Children share subset of parent’s resources
Parent and child share no resources
Execution
Parent and children execute concurrently
Parent waits until children terminate
Address space
Child duplicate of parent
Child has a program loaded into it
UNIX System::
fork() system call creates new process;
exec() system call used after a
fork() to replace the process’ memory space with a new program
Five states: New, Ready, Running, Blocked, Exit
- New : A process has been created but has not yet been admitted to the pool of executable processes.
- Ready: Processes that are prepared to run if given an opportunity. That is, they are not waiting on anything except the CPU availability.
- Running : The process that is currently being executed. (Assume single processor for simplicity.)
- Blocked : A process that cannot execute until a specified event such as an IO completion occurs.
- Exit : A process that has been released by OS either after normal termination or after abnormal termination (error).
main() {
int pid;
printf("Just one process so far\n");
pid = fork();
if (pid== 0) printf("I am the child\n");
else if (pid > 0) printf("I am the parent\n");
else printf("Error in fork()\n");
}