Process Management in Linux
Process Management in Linux
Linux
Foreground Processes
Depend on the user for input also referred to as interactive processes
Background Processes
Run independently of the user referred to as non-interactive or automatic processes
To view active processes and the current task lists in Linux we can use two popular
commands i.e. ps and top command. The ps command displays information about the
active programs or active processes on the system whereas the top command gives
you a real-time view of the active processes in the running system.
Types of Process Management in Linux
In Linux, there are two types of process management :
1. Foreground Processes:
Foreground processes are interactive processes that require user input. These
processes are executed in the foreground and are associated with a terminal.
Examples of foreground processes include editors, shells, and commands that require
user input. The Linux operating system provides several tools to manage foreground
processes. One of the most commonly used tools is the shell, which is a command-line
interface to the operating system. The shell allows the user to start, stop, pause, and
resume foreground processes. It also provides tools to monitor and manage the
resources used by these processes, such as virtual memory and CPU usage.
Another tool for managing foreground processes is the "ps" command, which displays
information about running processes. The "ps" command can be used to list all
processes or filter the list based on various criteria, such as the user who started the
process, the process ID (PID), and the process status.
The foreground process can also be managed using signals. A signal is a software
interrupt that is sent to a process to request it to take a specific action. For example,
the "Ctrl+C" signal is sent to a process to request it to terminate.
The foreground process can also be managed using job control commands. Job control
allows the user to start, stop, and resume foreground processes. The shell provides
several job control commands, such as "bg" to move a process to the background, "fg"
to move a process to the foreground, and "kill" to terminate a process.
2. Background Processes (Non-Interactive Processes):
Background processes are typically used for system services and daemon processes
that run continuously in the background. They can also be used for running long-
running jobs or task lists that do not require user interaction.
Linux provides several tools for managing background process execution. One of the
most commonly used tools is the "ps" command, which displays information about
running processes. The "ps" command can be used to filter the list of processes to
show only background processes.
Another tool for managing background processes is the "top" command, which
provides a real-time view of system processes, including background processes. The
"top" command can be used to monitor the resources used by background processes,
such as memory and CPU usage.
Background processes can be started using several methods. One method is to use
the "&" symbol at the end of a command, which runs the command in the background.
For example, the command "sleep 60 &" starts a process that sleeps for 60 seconds in
the background.
Another method for starting background processes is to use the "nohup" command,
which allows a process to continue running even after the user logs out. The "nohup"
command redirects the output of the process to a file system, which can be later
examined by the user.
Background processes can be managed using the "kill" command, which terminates a
process during execution. The "kill" command can be used with the process ID (PID) of
the background process or with a signal number to request a specific action.
1. ps: This command is used to display information about running processes. The
"ps" command can be used to list all processes or filter the list based on various
criteria, such as the user who started the process, the process ID (PID), and the
process status.
2. top: This command is used to display a real-time view of system processes. The
"top" command provides information about the processes running on the
system, including their resource usages, such as CPU and memory.
3. kill: This command is used to terminate a process. The "kill" command can be
used with the process ID (PID) of the process or with a signal number to request
a specific action.
4. nice: This command is used to adjust the priority of a process. Higher-priority
processes get more CPU time than lower-priority processes. The "nice"
command can be used to increase or decrease the priority of a process, which
affects its CPU usage.
5. renice: This command is used to change or adjust the priority of a running
process, which affects its CPU usage.
6. pkill: This command is used to send a signal to a process to request it to
terminate. The "pkill" command can be used with a current process name or a
regular expression to match multiple processes.
7. top: This command is used to display a real-time view of system processes. The
"top" command provides information about the processes running on the
system, including their resource usages, such as CPU and memory.
8. jobs: This command is used to display a list of background jobs running in the
current shell session.
9. fg: This command is used to move a background process to the foreground.
The "fg" command can be used with the job ID of the background process.
10. bg: This command is used to move a suspended process to the background.
The "bg" command can be used with the job ID of the suspended process.