Process:A program (object code) in execution.
Also, includes set of resources such as open files, pending signals, one or more threads of execution, an address space, internal kernel data structures and data section containing global variables.
Process id:Each process has a unique id called pid, used by system for identification.
Process spawning:New process is created and loading the new image in process address space. In Linux, it is done by fork followed by exec system call.
Fork:Creates a new process called child and duplicates the resources (other than pid, ppid and pending signals) from parent process address space to the child process address space. It returns twice from the kernel. Once is the parent process and again in the new born child.
Copy-on-write:Creates a new process and shares the resources from Parent process until anything written to address space. Here child runs first. Best for process spawning.
Vfork:Creates a new process and share the resources (other than page table entries) from parent process. After child runs exec or exit, parent process begins. Here the problem is, if exec failed in child, then parent process will never get executed. Best for process spawning.
Process states – Current status of the process. There are 5 process states
Task Running – List of tasks in run queue
Task Interruptible – Tasks which are sleeping and waiting for the condition to occur. It will respond to signal or interrupts.
Task uninterruptible – Same as Task interruptible. But it won’t respond to signals or interrupts.
Task Zombie – Task are completed. But waiting for the wait call from the parent process
Task Stopped – Tasks explicitly stopped by signals such as SIGKILL, SIGSTOP
Process context:When a program executes a system call or triggers an exception, it enters into kernel space. At this point, Kernel is said to be “Executing on behalf of the process” and is in process context.
Threads:There is no concept of threads in Linux. Here threads are the normal processes which share the resources with other processes.
Kernel Threads:There are certain operations will be done in background. It can be done by Kernel threads. But kernel threads exist only in kernel space and no process address space (mm pointer is NULL).
Process Termination:Processes are terminated by exit system call or return from the main () program or any signal/exception received.
But it releases the process, but not the process descriptor and enters into zombie state.
Removal of Process descriptor:Parent process calls wait system call to child process to get the status and it removes the process descriptor.
Zombie process:When child process is completed, it enters into zombie state till parent process invokes wait system call to child process.
Orphan process:Parent process exits before child process terminated which puts child process in zombie state for ever and wasting system memory by holding process address space. This child process is called orphan process.
Process scheduling:Scheduler -> Kernel subsystem for selecting which process to run next.
Preemption:Process of suspending the running process and invoking the high priority process.
Scheduler policy:
I/O bound processes:Process spends much of its time for submitting and waiting for an I/O. For example, Text editor.
- Low latency (Quick Response time) => High Priority
- short duration => Less timeslice value
Processor bound processes:Process spends much of its time for executing the program. For examples, video encoder.
- Not interactive process => Less priority
- Long duration => High Timeslice value
But some processes are both I/O bound and processor bound.
Process Timeslice:Amount of time the process to run until it is preempted.
Whenever the new child process is created, Half of the timeslice will be taken from parent process.
Whenever the timeslice of process expired, it will be recalculated.
Nice value – Priority of the process. It ranges from -19 to 20(default value is 0). Larger nice value corresponds to Low priority and Lower nice value for High priority.
Runqueue:Each processor will have runqueue which contains the list of all runnable process.
Waitqueue:Processes that are waiting for an external event to be occurred will be placed in waitqueue. As soon as the condition occurs, the process brings back to run queue for execution.
Init process:Invoked at the end of boot process and its Pid value is 1. Created statically by init_task, where as all other processes are created dynamically.