I was ignorant about processes and jobs, so I did some research.
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
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
Introducing an example of the ps command
Show all processes running by the current user
Add the a option in addition to the x option to see all processes running on your system, not just your own.
Also displays CPU and memory usage
A combination of frequently used machine options when executing ps commands
Display all processes of the user who executed the ps command together with detailed information To do
View all user processes with detailed information
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
hisotry
and grep git
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.
Command to display the current job list
A state in which processing is being executed while the user operates interactively
Command to run a job in the foreground
A state in which processing is being executed without the user interacting with it.
Command to put processing in the background
A state in which processing is temporarily suspended Ctrl + z Temporarily stop processing
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.
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
HUP INT QUIT ILL TRAP ABRT EMT FPE KILL BUS SEGV SYS PIPE ALRM TERM URG STOP TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ VTALRM PROF WINCH INFO USR1 USR2
Ctrl + z sends a TSTP (stop) signal and Ctrl + c sends an INT (end) signal for a foreground job.