ps, fg, bg, jobs, &, ctrl + z are all related to system tasks. Although these commands are basically not needed now, it is very practical to learn them
. & is most often used
. It is used at the end of a command and can put this command into the background to execute
two. ctrl + z
can put a command that is executing in the foreground into the background, and pause
three. jobs
to see how many commands are currently running in the background
four. fg
transfers the command in the background to the foreground and continues to run.
If there are multiple commands in the background, you can use fg %jobnumber to call out the selected command. %jobnumber is the serial number of the command being executed in the background found through the jobs command (not pid). )
five. bg
turns a command suspended in the background into continuous execution.
If there are multiple commands in the background, you can use bg %jobnumber to call out the selected command. %jobnumber is the serial number of the command being executed in the background found through the jobs command ( not pid)
Six, ps
Display the currently running process, pay attention to the difference with jobs, jobs display the process running on the current terminal (not necessarily background running), jobs display the command running in the background
# Use Shell commands to control task Jobs execution under Linux
ps lists running processes on the system ;
kill sends a signal to one or more processes (often used to kill a process);
jobs lists the status of tasks started in the current shell environment , if jobsid is not specified, all active task status information is displayed; if the termination of a task is reported (that is, the status of the task is marked as Terminated), the shell removes the task's process ID from the list known to the current shell environment;
bg moves the process to the background (Background);
fg moves the process to the foreground (Foreground);
moves the job to the background
If you often work under X graphics, you may have this experience: run a GUI through terminal commands The program, the GUI interface comes out, but your terminal is still in place, you can't continue to execute other commands in the shell, unless you close the GUI program.
In order to make the terminal continue to accept commands after the program is executed, you can move the process to the background and run the program with the following command: #Suppose you want to run xmms
$xmms &
After opening xmms, the terminal prompt comes back. Now xmms is running in the background; but in case you forget to use "&" when running the program, and don't want to re-execute it; you can use ctrl+z to suspend the program, and then type the bg command, so that the program continues to run in the background .
Concept:
If the current task has 2 task numbers in the background, [1], [2]; if the first background task is successfully executed and the second background task is still being executed, the current task will automatically become Background task for background task number "[2]". So it can be concluded that the current task will change. whenWhen the user enters commands such as "fg", "bg", and "stop", if no quotation marks are added, all the changes are the current task.
Viewing jobs
Use the jobs or ps command to view running jobs.
The result of the jobs command execution, + indicates a current job, the minus sign table is a job after the current job, the jobs -l option can display the PIDs of all tasks, and the status of jobs can be running, stopped, Terminated, but If the task is killed (kill), the shell removes the task's process id from the list known to the current shell environment; that is, the jobs command displays backgrounds that are running or suspended in the current shell environment Task information;
process suspension Suspend of
background process:
execute through the stop command in solaris, check the job number (assuming num) through the jobs command, and then execute stop %num;
in redhat, there is no stop command, you can pass Execute the command kill -stop PID to suspend the process;
when the currently suspended task is to be re-executed, the status of the suspended job can be changed from stopped to running through bg %num, and it is still executed in the background; when needed When it is executed in the foreground, execute the command fg %num;
the suspension of the foreground process:
ctrl+Z; the termination of the process;
the termination of the
background process:
Method 1:
Check the job number (assuming num) through the jobs command, and then execute Kill %num
Method 2:
View the process ID (PID, assuming pid) of the job through the ps command, and then execute kill pid
Termination of foreground process: Other functions of
ctrl+c kill In addition to terminating the process, kill can also send other signals to the process. Use kill -l to view the signals supported by kill. SIGTERM is a signal sent by kill without parameters, which means that the process is to be terminated, but it depends on whether the process supports it or not. If the process has not terminated, you can use kill -SIGKILL pid, which is terminated by the kernel, and the process cannot listen for this signal.
Attachment: nohup command reference
附:nohup命令参考