Question one: see which process is consuming which port, and kill the process
1. View occupied ports: sudo lsof-i: 80
lsof command is the meaning of list open files
Like what:
lsof filename Displays all processes that open the specified file
Lsof-i used to display conditions (4, 6, protocol, port, @ip) for eligible processes
2. According to PID kill process: sudo kill 1000 (process number)
Kill command syntax is kill [signal or option] PID (s)
Use Kill-l to view all signals
Like kill a process is kill SIGKILL pid or kill-9 pid here-9 represents SIGKILL
There is also the Pkill command, which is used to kill the process of matching names, and can be used to match names with regular matches.
And Killall is killing all the same names.
Issue two: Let the process run in the background
Turn on the terminal to execute a longer command (or log on to the remote server to execute the command), and then the end result task terminates. But our idea is to let it execute in the background, and to shut down the terminal will not terminate.
Shut down the terminal causes the task to terminate: when the user logs off (logout) or the network disconnects, the terminal receives a HUP (hangup) signal to close all its child processes. So there are two ways to do this: either let the process ignore the HUP signal or let the process run in a new session to become a child process that does not belong to this terminal.
Resolve command: use Nohup or Setsid
First, Nohup
The use of nohup is very convenient, just add nohup before the command to be processed, standard output and standard error-deficient capital are redirected to the Nohup.out file. Can be used ">filename 2>&1"
to change the default redirection file name. Adding ' & ' at the end allows the command to run in the background
For example:
Nohup python3 manage.py runserver .... &
The parent ID of this process is still the PID of this terminal.
Second,Setsid
Setsid Ping www.ibm.com
The parent ID for this task is the INIT process ID, 1, which is different from the previous command.
Also: Here's a little tip about Subshell. We know that the inclusion of one or more names in the "()" allows these commands to run in a child shell, which expands a lot of interesting functionality, and one of the things we're going to talk about right now.
For example
(Ping www.ibm.com &)
The parent ID (PPID) of the newly submitted process is found to be 1 (PID of the Init process), not the process ID of the current terminal. Therefore, it does not belong to the sub-process of the current terminal, so it will not be affected by the HUP signal of the current terminal.
Source: http://www.ibm.com/developerworks/cn/linux/l-cn-nohup/
Linux using small notes < process actions >