The combination of the memory occupied by the program and all of its state (which also includes details of what files it currently has open) is called a process. We can manage and manipulate processes with Bash commands. Processes can be run in parallel with the shell with the command &. Unix has a number of system calls that manage processes.

echo hello &  
[1] 32466  # process id of child
hello

If it is a single CPU system only one program can run at a time. The Unix kernel is responsible for switching between programmes. This depends on the CPU feature called the interrupt. This is where the running program is interrupted and its state (memory, CPU registers) is saved, and the kernel is entered. Later the kernel can restore the state and restart the program.

Basic commands

CommandDescriptionRef
psList all current running processes[[#list-all-processes-ps
bgSend a task to background
fgBring a task to foreground
<Ctrl+Z>Pause a running process
<Ctrl+C>Terminate a running process
nice <lv> -p <PID>Start a process with specified priority level
renice <lv> -p <PID>Change the priority level of existing process

List all processes (ps)

With ps al | more command, the bash lists all current processes in a long format and display it in one screenful at a time.

  • Owner User ID (UID) Is a numerical identifier associated with a user account in the system. We can map the UID into a name using the password file stored in the /etc/passwd.
  • Process ID (PID) Each process on the system is assigned a PID, which is used to track and manage processes.
  • Parent Process ID (PPID) The Parent Process ID (PPID) is the PID of the parent process that created or spawned a new child process.
  • Priority (PRI) Priority determines the order in which processes are executed on the CPU. Lower numeric values indicate higher priority, and higher numeric values indicate lower priority. The priority value can be negative.
  • Command It is the name of the file or command that initiated the process.

Password file

The password file is structured in a specific format, with colon-separated fields. Each line in the file represents a user account on the system. Consider the following example:

cat /etc/passwd
info1112:x:1003:1004:Bob Kummerfeld,,,:/home/info1112:/bin/bash
  • Username (Login Name): info1112
  • Password Placeholder: x
  • User ID (UID): 1003
  • Group ID (GID): 1004
  • User Information (GECOS): Bob Kummerfeld,,,
  • Home Directory: /home/info1112
  • Login Shell: /bin/bash

Options

  • All processesps a: List all current processes.
  • Long format ps l: List processes in a long format.

Operating_systemBash_programmingBash_scriptingProcess_management