Linux closes signals related to the switching process: SIGINT, SIGKILL, SIGTERM, SIGSTOP

reference

The difference between ctrl-c, ctrl-z, ctrl-d in Linux
ctrl-d (Terminate input, or exit shell) is a special binary value that represents EOF, which is equivalent to typing exit in the terminal and then pressing Enter;
ctrl-/ sends SIGQUIT signal to all processes in the foreground process group, terminates the foreground process and generates a core file;
ctrl-s interrupts the console output;
ctrl-q resumes the console output;
ctrl-l clears the screen.

Linux commands kill and signal
kill <pid> : Send the SIGTERM signal to the specified process. If the process does not capture the signal, the process terminates.
kill -l: List all signal names and values.
kill -l <signame>: Display the value of the specified signal.
kill -9 <pid>: Forcefully kill the specified process and terminate the specified process unconditionally.
kill %<jobid>: Kill the specified task (use the jobs command to list).
kill -QUIT <pid>or kill -3 <pid>: Make the program exit normally.

Basic knowledge

  1. Use kill -lcommands to view signal types
    Insert picture description here
  2. The difference between the foreground process and the background process in
    Linux : The LINUX background process is also called the daemon , which is a special process running in the background. It is independent of the control terminal and periodically performs certain tasks or waits for certain events to occur. Generally used as a system service , you can use crontab to submit ( Linux crontab is a command used to execute programs regularly ), edit or delete the corresponding job. Guarding means not being controlled by the terminal . Most Linux servers are implemented using daemons. For example, Internet server inetd, Web server httpd, etc. At the same time, the daemon completes many system tasks. For example, the job planning process crond, the printing process lpd, etc.
  3. The following are the commonly used signals:
    HUP 1 terminal disconnection
    INT 2 interrupt (same as Ctrl + C)
    QUIT 3 exit (same as Ctrl + \)
    TERM 15 terminate
    KILL 9 force termination
    CONT 18 continue (in contrast to STOP, fg/bg command)
    STOP 19 Pause (same as Ctrl + Z)

SIGINT signal

ctr+c trigger: (kill foreground process) sends a SIGINT signal to all processes in the foreground process group , forcibly terminating the execution of the program; (INT -> interrupt) -> can only terminate all processes in the foreground process group

SIGSTOP signal

ctrl+z trigger: (suspend foreground process) Send a SIGSTOP signal to all processes in the foreground process group. It is often used to suspend a process instead of ending the process. The user can use the fg/bg operation to resume the execution of the foreground or background process.

fg, bg let your process switch between the front and the background.
Add at the end of a command &, you can put this command in the background for execution. Such as ./build/Server &
jobsinstructions: check how many commands are currently running in the background.
fgInstructions: transfer the commands in the background to the foreground and continue to run.
bgInstructions: change a command that is paused in the background to continue execution

SIGTERM signal and SIGKILL signal

kill <PID>Send the SIGTERM signal to the specified process. If the process does not capture the signal, the process terminates. SIGTERM is the end of the program (terminate) signal, which is different from SIGKILL in that the signal can be blocked and processed.
Linux C practice (1): Signals that cannot be ignored or captured-SIGSTOP and SIGKILL Signals in
linux SIGINT SIGTERM SIGKILL
SIGKILL: kill -9 <PID>This signal will be sent to force the process to end immediately.
SIGKILL cannot be caught. After receiving this signal, the program will definitely exit. This is why it kill -9must be guaranteed to kill the program.

Example 1

Start the server process in the foreground -> ctrl+z suspend the foreground process, make it enter the background and pause -> bg continue the execution of the suspended command in the background -> fg transfer the command in the background to the foreground to continue running -> ctrl+c End the foreground process.
Insert picture description here

Example 2

The start server command is added &at the end , the server executes in the background -> ctrl+c cannot end the background server process -> kill pidsends the SIGTERM signal to end the server process.
Insert picture description here

Guess you like

Origin blog.csdn.net/XindaBlack/article/details/106956137