0% found this document useful (0 votes)
3 views

Process Management in Linux

Uploaded by

vishnup22102002
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Process Management in Linux

Uploaded by

vishnup22102002
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Commands for Process Management in

Linux

Process management is an essential component of the Linux operating system. Linux


is known for its robust and stable performance, and it owes a lot to its process
management capabilities. In simple terms, a program in execution is considered a
process. The code is available in a readable format in an executable file inside a
program's address space. The elements of activity inside a process are called threads
and every thread has a unique program counter. This subsystem is responsible for
managing all the processes and task lists on a Linux system. This article will discuss
the basics of process management, types of process management, and commands
used to manage these processes in Linux.

A process in Linux is nothing but a program in execution. It’s a running instance of a


program. Any command that you execute starts a process.
Types of Processes in Linux

In Linux processes can be of two types:

 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

Stages of a Process in Linux


In Linux, a process goes through several stages during its lifetime. Understanding
these stages and checking how they run in the background is important for process
management and troubleshooting. The states of a process in Linux are as follows:

1. Created: A process is created when a program is executed. At this stage, the


process is in a "created" state, and its data structures are initialized.
2. Ready: The process enters the "ready" state when it is waiting to be assigned to
a processor by the Linux scheduler. At this stage, the process is waiting for its
turn to execute.
3. Running: The process enters the "running" state when it is assigned to a
processor and is actively executing its instructions.
4. Waiting: The process enters the "waiting" state when it is waiting for some
event to occur, such as input/output completion, a signal, or a timer. At this
stage, the process is not actively executing its instructions.
5. Terminated: The process enters the "terminated" state when it has completed
its execution or has been terminated by a signal. At this stage, the process data
structures are removed, and its resources are freed.
6. Zombie: A process enters the "zombie" state when it has completed its
execution but its parent process has not yet read its exit status. At this stage, the
process details still have an entry in the process table, but it does not execute
any instructions. The zombie process is removed from the process table when
its parent process reads its exit status.

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 process management in Linux refers to the management of processes that


run in the background and do not require user interaction. These processes are also
referred to as non-interactive processes and automatic processes. These processes
can be started by the operating system or by a user, and they do not have an
associated terminal.

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.

Commands Used to Manage Processes in


Linux
There are several commands used in process management in Linux. Here are some of
the most commonly used commands:

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.

You might also like