Technical skill

Linux commands: process management

See which programs are running

Open a browser and a music app: each is a program, and each running copy is a process. A program can start helper processes, so one app may appear as several processes. The operating system keeps track of them so it can share resources and manage work. Linux's core, called the kernel, gives each process a process ID, or PID, and records its parent process ID (PPID), state, credentials, and relationships to other processes.

A process can also contain threads, which are smaller paths of work inside that process. A process listing normally shows one entry per process; thread-aware options can show individual threads. A job is different: it belongs to the interactive shell that started it and may contain one process or a whole pipeline. A job number such as %1 is not a PID. jobs shows the current shell's jobs, not every process on the machine.

ps takes a snapshot of processes at the moment it runs. This compact view includes IDs, state, and command name:

ps -eo pid,ppid,stat,comm

The STAT column uses state letters. R means running or ready to run, S means interruptible sleep, and Z means a terminated child whose parent has not collected its exit status. A zombie no longer runs, but its table entry remains until the parent reaps it. ps -ef shows a different, widely used format with more command-line detail. pgrep -a pattern searches process names and prints matching command lines; inspect matches because a broad pattern can find several processes.

A signal is a short notice sent to a process to request an action. kill without a signal usually sends SIGTERM, which gives a program a chance to handle the request and clean up. SIGKILL cannot be caught or ignored, so the program cannot handle it or save work first. Check which process a PID belongs to before sending a signal. For example, after verifying PID 4242, ask it to exit and then inspect whether it remains:

kill -TERM 4242
ps -p 4242 -o pid,stat,comm

A PID can be reused after a process exits. If time passes before sending another signal, inspect the current process again instead of trusting an old number. Permission matters too: a process can normally signal itself and processes owned by the same user; signaling another user's process may need elevated permission.

For a command from the current shell, fg brings a stopped or background job to the foreground and bg resumes a stopped job in the background. wait collects the exit status of a child or job started by that shell. It cannot wait for any process on the system. A service manager may restart a supervised process after it exits, so use that manager's status and controls when the process belongs to a service.

Interactive exercises

Materials

Skillsets
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Skillset Skyeng Senior PlatOps preview
image descriptionSkyeng Senior PlatOps
by Artem Naumenko (slack2)
7 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Skillset Skyeng Ops (for DevOps) preview
image descriptionSkyeng Ops (for DevOps)
by Roman Burnashev
2 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful