[LINUX] Investigated processes and jobs

I was ignorant about processes and jobs, so I did some research.

What is a process?

A process is a program that is running in memory.

Each process is given a unique ID called the process ID, which allows the process to be managed appropriately. The process ID does not change until the process ends.

The process has an execution user set like the owner of the file, and cannot operate other people's processes.

When a new process is created, another process is created from the existing process. The original process is called the parent process, and the created process is called the child process. As a concrete example, when the ls command is executed, the parent process becomes the shell process and the child process becomes the ls command process.

In Linux, in addition to the process running by the logged-in user, the process of managing the Linux system itself is running from the beginning. Many of these are running with superuser privileges

ps command

A command that displays the processes that are currently running. When run without options, only the processes running in the current terminal are displayed.

Execution example

PID TTY           TIME CMD
89124 ttys000    0:00.05 /Applications/iTerm.app/Contents/MacOS/iTerm2 --server <=Iterm process
89126 ttys000    0:00.32 -zsh <=zsh related
88296 ttys001    0:01.40 /usr/local/bin/zsh -l <=zsh related

options for the ps command

Introducing an example of the ps command

x option

Show all processes running by the current user

a option

Add the a option in addition to the x option to see all processes running on your system, not just your own.

u option

Also displays CPU and memory usage

Frequently used options

A combination of frequently used machine options when executing ps commands

ux option

Display all processes of the user who executed the ps command together with detailed information To do

aux option

View all user processes with detailed information

What is a job?

A unit of processing when viewed from the shell is called a job (a process is a unit of processing when viewed from the kernel). One line entered on the shell command line becomes one job

Execution example history | grep git

Processes have a system-wide unique process ID, but jobs have a job number for each shell. In other words, if multiple terminals are opened and multiple shells are used at the same time, the job numbers will be duplicated.

jobs command

Command to display the current job list

Job status


A state in which processing is being executed while the user operates interactively

fg command

Command to run a job in the foreground


A state in which processing is being executed without the user interacting with it.

bg command

Command to put processing in the background


A state in which processing is temporarily suspended Ctrl + z Temporarily stop processing

Summary of job state transitions

kill command

A command used to terminate a process or background job. To be exact, the "send signal" command. A signal is a signal sent to a process.

It behaves in various ways such as "end", "stop", and "restart" depending on the type of signal. By sending a signal to a running process, it is possible to communicate between the processes.

Signal sent by kill command

The type of signal sent by the kill command can be specified with kill-<signal name>. If the signal name is omitted, the signal TERM is sent as the default value. That is, the following two commands have the same meaning.

kill 100 kill =TERM 100

TERM means terminate.

In addition, the signal has a signal number, and options can be specified by the signal number. The signal number of TERM is 15, and kill -15 100 has the same meaning as the above command.

You can check the signal type with kill -l

$ kill -l

Ctrl + z sends a TSTP (stop) signal and Ctrl + c sends an INT (end) signal for a foreground job.

Recommended Posts

Investigated processes and jobs
About LINUX files and processes