Processes (Processes) | Linux

2024/01/20

In Linux, processes (Processes) are instances of running programs in the system. Each process consists of one or more threads that run on the system, performing various tasks and operations. The Linux operating system uses processes as the basic unit for managing and executing tasks.

Here are some important concepts about Linux processes:

  1. Process ID (PID): Each process has a unique identifier called the Process ID. The PID is a number used to identify and manipulate processes.
  2. Parent and Child Processes: In Linux, a process can spawn other processes. The spawning process is called the parent process, and the newly created process is called the child process. Parent and child processes can communicate with each other.
  3. Process States: A process can be in different states, including running, waiting, stopped, killed, etc. These states reflect the running status of the process in the system.
  4. Process Priority: The priority of a process determines the order in which it runs on the CPU. Processes with higher priority get CPU resources first.
  5. Process Groups: Processes can form process groups, which are a set of related processes. This organizational method makes it easier for processes to collaborate and communicate.
  6. Foreground and Background Processes: A foreground process is the one currently interacting with the user, while a background process runs in the background without requiring direct user involvement.
  7. Zombie Processes: When a process finishes running but its parent process has not yet reclaimed its resources, the process becomes a zombie process. The existence of zombie processes is undesirable because they consume system resources.
  8. Process Priority: Process priority is a numerical value that represents the execution priority of a process on the CPU. Processes with higher priority get CPU resources first.

In Linux, you can use some common commands to view and manage processes, such as:

We can use & to run a program in the background

sleep 10 &

We can use kill -9 to terminate a process

kill -9 <PID>
kill -SIGKILL <PID>

View processes used by everyone on the system

ps aux

Other common operations

# Run a process
sleep 1000
# Then use Ctrl + Z (suspended process)
# Ctrl + C will kill the process

# Run in the background from the start
sleep 1000 &

# Display all background processes
jobs

# Resume the suspended process
zsh  => bg %<job id>
bash => bg <job id>

# Re-enter the interactive interface of the process
zsh  => fg %<job id>
bash => fg <job id>
  • ps: Display a list of running processes in the system.
  • top: Display system resources and process information in real time.
  • kill: Terminate a specified process.
  • nice: Adjust the priority of a process.
  • killall: Terminate all processes with a specified name.

These commands make it convenient to manage and monitor processes in the system.