SysCalls and Process States¶
Statement¶
- Read the resources below on system calls and process states:
- Explain how Linux utilizes processes, call them, and then also utilize states and eventually end processes to manage all the applications and other services within a computer environment.
Solution¶
Linux uses virtualization to share resources and give the sense of multiple processes running simultaneously. Processor virtualization relies on time-sharing, context-switching mechanisms, and high-level scheduling policies to decide which process can utilize the processor and for how long.
A Process represents an executable program that utilizes the CPU to do calculations. A process is usually created by another process, except the OS primary process, which usually is created automatically on the system’s booting. The life of a process starts by loading its code (and data) into memory, then takes its turn on the CPU to its work until its code (and data) gets unloaded from memory, terminating its existence and freeing resources for another process to take them over.
During its life, a process always has a status; this status changes over time depending on the current situation and internal and external circumstances (e.g. related to other processes or other parts of the system).
A Process starts with a NEW (RUNNABLE) state, waiting for the scheduler to put it in the proper schedule transforming its state to STOPPED; then, when this process gets a turn on the CPU, its state changes to RUNNING. If a process expects I/O data, its state changes to UNINTERRUPTABLE_SLEEP until I/O responds and changes its state to STOPPED, waiting -again- for turn on the CPU to change to RUNNABLE. When a process has to stay idle for a long time, its state changes to INTERRUPTABLE_SLEEP; so that it can go back quickly to RUNNABLE when needed. During its termination, a process state changes to ZOMBIE.
The OS keeps track of all processes on the machine using some data structures (usually queues). The OS puts the process (its PCB) into the appropriate structure depending on its state. The OS moves PCBs between queues when their state changes. PCB usually contains all data around the process, allowing the CPU to continue executing from where it left off the last time that state changed.
Processes manage other processes using System calls. System calls are subroutines that reside in the OS kernel and are intermediate in managing hardware. System calls usually communicate directly with hardware drivers and have kernel mode access, allowing them to manage resources -almost- as the OS needs.
There are different types of system calls, and their functionality groups them as Process Control System calls, File Management, Device Management, Maintenance and Communication system calls.
The group that matters to us now is Process Management. The OS expose some functions to control processes, and any program can use these calls to manage processes actively.
The most famous process management system calls are:
Fork()
: creates a new process from inside a process by copying the parent into the child, then changing the child accordingly.Wait()
: waits for a specific process to terminate before moving on to the next instruction.Exec()
: runs a process within the current process by replacing the stack and heap of the parent process with the child ones.Kill()
: terminates a process.Signal()
: catches an external signal during execution and adequately handles it.
References¶
- Arpaci-Dusseau, R. H., & Arpaci-Dusseau, A. C. (2018). Operating systems: three easy pieces (1.01 ed.). Arpaci-Dusseau Books. Retrieved June 16, 2022, from https://pages.cs.wisc.edu/~remzi/OSTEP/
- Operating system - Process scheduling. (n.d.). Biggest Online Tutorials Library. https://www.tutorialspoint.com/operating_system/os_process_scheduling.htm