Process/ Service States and Lifecycle
Mahinsha Nazeer

Mahinsha Nazeer @mahinshanazeer

About: Certified engineer—just one loose nut away from a total breakdown

Location:
Hyderabad, India
Joined:
Apr 14, 2025

Process/ Service States and Lifecycle

Publish Date: Apr 20
0 0

In Linux, a process can exist in various states throughout its lifecycle, including running, sleeping, stopped, and zombie states. A process starts with creation using the fork() system call, creating a child process as a copy of the parent. It then moves to the running state, where it executes instructions, switching between running and runnable based on CPU availability. If it needs to wait for resources or events, it enters a sleeping state, which can be interruptible or uninterruptible. A process can be stopped by signals like SIGSTOP and resumed with SIGCONT. Upon completion, it enters the zombie state until its parent process reads its exit status using wait() or waitpid(). Monitoring these states can be done using commands like ps, top, and htop, which provide insights into the current status of processes and help manage system resources effectively.

An existing parent process duplicates its own address space, which is known as a process fork, to create a child process structure. Every new process is assigned a unique process ID (PID) for tracking and security purposes. The PID and the parent’s process ID (PPID) are elements of the new process environment. Any process can create a child process. All processes are descendants of the first system process, systemd, on a Red Hat system.


Process Life cycle

In a multitasking operating system, each CPU (or CPU core) can be working on one process at a time. As a process runs, its immediate requirements for CPU time and resource allocation change. Processes are assigned a state, which changes as circumstances dictate.

The following diagram and table describe Linux process states in detail:

Listing Processes

The ps command is used for listing detailed information for current processes.

  • User identification (UID), which determines process privileges
  • Unique process identification (PID)
  • Amount of used CPU and elapsed real time
  • Amount of allocated memory
  • The process stdout location, which is known as the controlling terminal
  • The current process state.

Process Control with Signals

A signal is a software interrupt that is delivered to a process. Signals report events to an executing program. Events that generate a signal can be an error, an external event (an I/O request or an expired timer), or by the explicit use of a signal-sending command or keyboard sequence.


kill -1 : To list the names and numbers of all available sgnals
ps -aus | grep process : to grep the pid and details of proces
pgrep process : to sort the pid alone
pkill 'process' : to kill all the process with corresponding process name.
killall 'process' : will only terminate processes named exactly 'process', no partial match names or patterns.
Enter fullscreen mode Exit fullscreen mode

In summary, understanding the process states and lifecycle in Linux is crucial for effective system management. Processes transition through various states such as running, sleeping, stopped, and zombie, each indicating different stages of execution and resource usage. Tools like ps, top, and htop are invaluable for monitoring these states, providing real-time insights and helping administrators manage system performance and troubleshoot issues efficiently. This knowledge ensures that you can maintain a stable and responsive Linux environment.

Reference: https://rol.redhat.com/rol/app/courses/rh124-9.3/

Comments 0 total

    Add comment