Process
A program/command when executed, a special instance is provided by the system to the process. This instance consists of all the services/resources that may be utilized by the process under execution.
Whenever a command is issued in Unix/Linux, it creates/starts a new process.
Through a 5 digit ID number Unix/Linux keeps an account of the processes, this number is called process ID or PID. Each process in the system has a unique PID.
Used up pid’s can be used in again for a newer process since all the possible combinations are used.
At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process.
Initializing a process
A process can be run in two ways:
Foreground Process
Every process when started runs in foreground by default, receives input from the keyboard, and sends output to the screen. When issuing pwd command
When a command/process is running in the foreground and is taking a lot of time, no other processes can be run or started because the prompt would not be available until the program finishes processing and comes out.
Background Process
It runs in the background without keyboard input and waits till keyboard input is required.
Thus, other processes can be done in parallel with the process running in the background since they do not have to wait for the previous process to be completed.
Adding & along with the command starts it as a background process
Since pwd does not want any input from the keyboard, it goes to the stop state until moved to the foreground and given any data input. Thus, on pressing Enter.
Commands
ps (Process status) can be used to see/list all the running processes.
Stop Process
When running in foreground, hitting Ctrl + c (interrupt character) will exit the command. For processes running in background kill command can be used if it’s pid is known.
If a process ignores a regular kill command, you can use kill -9 followed by the process ID.
bg command
A job control command that resumes suspended jobs while keeping them running in the background
fg command
It continues a stopped job by running it in the foreground.
top command
This command is used to show all the running processes within the working environment of Linux.
nice command
It starts a new process (job) and assigns it a priority (nice) value at the same time.
nice value ranges from -20 to 19, where -20 is of the highest priority.
renice command
To change the priority of an already running process renice is used.
df command
It shows the amount of available disk space being used by file systems.
free command
It shows the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
Types of Processes
Parent and Child process
The 2nd and 3rd column of the ps –f command shows process id and parent’s process id number.
For each user process, there’s a parent process in the system, with most of the commands having shell as their parent.
Zombie and Orphan process
After completing its execution a child process is terminated or killed and SIGCHLD updates the parent process about the termination and thus can continue the task assigned to it.
But at times when the parent process is killed before the termination of the child process, the child processes become orphan processes, with the parent of all processes “init” process, becomes their new pid.
A process which is killed but still shows its entry in the process status or the process table is called a zombie process, they are dead and are not used.
Daemon process
They are system-related background processes that often run with the permissions of root and services requests from other processes, they most of the time run in the background and wait for processes it can work along with for ex print daemon.
Last updated