Controlling Process
Controlling Process
Components of Process
● A process represents a running program.
● It’s the abstraction through which memory, processor time, and I/O resources
can be managed and monitored.
● A process consists of an address space and a set of data structures within the
kernel.
● The address space is a set of memory pages that the kernel has marked for
the process’s use
PID: process ID number
● A process’s UID is the user identification number of the person who created
● The EUID is the “effective” user ID, an extra UID that determines what
resources and files a process has permission to access at any given moment.
GID and EGID : real and effective group ID
● If the process has designated a signal handler for that particular signal, the
handler routine is called. The handler receives information about the context
in which the signal was delivered.
● If no handler is designated for the signal, the kernel takes some default action
on behalf of the process
Kill and Killall
kill
● The kill command is most often used to terminate a process. kill can send any
signal, but by default it sends a TERM
● The syntax is
● A kill without a signal number does not guarantee that the process will die,
because the TERM signal can be caught, blocked, or ignored.
killall
● kills processes by name.
● For example, the following command kills all Apache web server processes:
● The pkill command searches for processes by name and sends the specified
signal.
Process State
Suspend AND Resume State
● The STOP and CONT signals allows for the suspension and resumption of
processes.
● The STOP signal suspends a process, pausing its execution.
● Conversely, the CONT signal resumes a previously stopped process,
allowing it to continue its execution from where it was halted.
● These signals affect the entire process and are not specific to individual
threads within the process
● Execution and waiting State :While a process may be considered runnable,
individual threads within that process often need to wait for the kernel to
perform certain tasks on their behalf before they can continue execution.
● Thread Sleep State: During the waiting period described above, the thread
enters a short-term sleep state, during which it cannot execute.
nice and renice
● The nice command is used to launch a new process with a modified
scheduling priority (niceness).
● In this, if we give a process a higher priority, then Kernel will allocate more
CPU time to that process.
● The range of allowable niceness values varies among systems. In Linux the
range is -20 to +19
● Lower values represent higher priorities, while higher values represent lower
priorities.
● Unless the user takes special action, a newly created process inherits the
niceness of its parent process.
● A process’s niceness can be set at the time of creation with the nice
command and adjusted later with the renice command.
renice
● The renice command is used to change the scheduling priority (niceness) of
already running processes
● It allows you to adjust the priority of a process by specifying its PID, process
group ID (PGID), or user.
● Example: renice +10 -p 1234 will increase the priority of the process with PID
1234 by 10.
ps
● The ps command is the system administrator’s main tool for monitoring
processes.
● ps can show the PID, UID, priority, and control terminal of processes.
● It also informs you how much memory a process is using, how much CPU
time it has consumed, and what its current status is
● You can obtain a useful overview of all the processes running on the system
with ps aux. The a option says show all processes, and x says show even
processes that don’t have a control terminal; u selects the “user oriented”
output format .
Example : $ps aux
top
● top command is used to show the Linux processes.
● It provides a dynamic real-time view of the running system.
● Usually, this command shows the summary information of the system and the
list of processes or threads which are currently managed by the Linux Kernel
The /proc filesystem
● The /proc filesystem in Linux is a virtual filesystem that provides a view into
the kernel's internal data structures and system parameters.
● /proc is often referred to as a "pseudo-filesystem" because it doesn't contain
real files on disk. Instead, it is a virtual filesystem that the kernel generates
dynamically to expose various system information and statistics to user-space
processes.
● The /proc filesystem contains a wide range of information about the system,
including details about running processes, memory usage, CPU utilization,
hardware configuration, and kernel parameters
● One of the primary purposes of /proc is to provide detailed information about
running processes.
● Each process is represented by a directory named with its Process ID (PID)
within the /proc directory.
● Inside each process directory, there are various files containing information
such as command line arguments, memory maps, file descriptors, and more.
● Many system parameters and settings can be dynamically adjusted by writing
to special files within the /proc filesystem
strace
● This commands display every system call that a process makes and every
signal it receives
● strace is a powerful debugging tool available in Linux systems, often used to
inspect the behavior of running processes at a low level.
● strace is designed to intercept and record the system calls made by a
process, providing insight into its behavior, interactions with the kernel, and
potential errors
● You can attach strace to a running process to observe its system calls in
real-time, or you can launch a new process with strace to monitor its behavior
from the start.
Functionality
● strace displays every system call made by the process, including details such
as the call name, arguments passed to the call, and the result code returned
by the kernel
● It decodes system call arguments, making it easier to understand the purpose
of each call.
● Errors that occur during system calls, such as filesystem permission errors or
socket conflicts, are often evident in the strace output
Runaway processes
● A runaway process refers to a program or process that consumes an
excessive amount of system resources, such as CPU, memory, disk, or
network bandwidth, beyond what is expected or reasonable for its normal
operation.
● Runaway processes can be identified by observing their abnormal
consumption of system resources.
● This can be seen through tools like ps, top, or uptime, which provide
information about CPU usage, memory consumption, and system load
averages.
● High CPU utilization, excessive memory usage, or consistently high system
load averages are common indicators of runaway processes
● Runaway processes may result from various factors, including software bugs,
inefficient implementation, or failure to handle upstream failures gracefully