Linux Shell using the following command to perform control tasks Jobs, Linux background process management, and ctrl + z

First, the following command can be used to manipulate the process tasks:

ps lists running processes in the system.

kill sends a signal to one or more processes (often used to kill a process).

jobs listed in the current shell environment task status has been started, if not specified jobsid , task status information is displayed for all activities; if reported terminate a task (that is, the task of the state is labeled Terminated ), shell from the current shell environmental known list, delete a task process ID.

bg will move to the background process (Background).

fg will move to the foreground process (Foreground).

Second, the job is transferred to the background

If you often work in X graphics, you might have this experience: to run a GUI program through the terminal command, GUI interface out, but your terminal also stay in place, you can not continue with other commands in the shell, unless the GUI program off.

In order to make the program after executing terminal can continue to accept commands, you can move the process running in the background, use the following command to run the program: $ xmms & (# Suppose you want to run xmms , a program)

This opens xmms after indicating that the terminal is back. Now xmms running in the background yet; but if forget to use "when you run the program & ", and do not want to re-run; you can first use the [CTRL] + [Z] suspended the program, and then typing bg command, so that the program continue running in the background.

Third, the concept: the current task

If there is a background task number two, [1], [2]; if when the first successful implementation of a background task is completed, a second background task is still running, the current task will automatically become a background task number " [2] "background task. So little can be drawn that the current task will change. When a user enters " fg ", " BG " and " STOP when" and other commands, if you do not add any quotation marks, then the changes are the current task.

Fourth, look at jobs

Use jobs or ps command to look at jobs being performed.

jobs results of command execution, + (plus sign) represents a current job, - (build number) represents a job after a current job, jobs the -l (lowercase love of l) option to display all tasks PID, jobs status can be runningstoppedterminated , but if the task is terminated ( the kill ), shell from the current shell environment delete a task known process identification list; that is, jobs command displays the current shell environment It plays in the background running or suspended task information.

Fifth, the process hangs

1, background processes pending:

In Solaris (system) by stop executes commands jobs view command job number (assumed NUM) , and then performs stop NUM% .

In redhat (system) , there is no stop command, the command can be executed by the kill -stop PID , the process is suspended.

When you want to re-execute the current task being suspended by bg% num can be suspended job state by the stopped changed to running , still in the background; if need be changed in the foreground, execute the command fg% num namely can.

2, foreground process hangs:

【Ctrl】+【Z】

Terminate six process

1, a background process termination:

method one:

By jobs command to check the job number (assumed to NUM ), and then execute the kill% NUM .

Method Two:

By ps command to check the job's process ID ( PID , assumed pid ), and then execute the kill pid .

2, foreground process termination:

【Ctrl】+【C】

3, the other roles kill

kill in addition to terminate the process, but also to send a signal to other processes using the kill -l (love of l) can be viewed kill signal support.

SIGTERM is no parameter kill signal sent, meant to termination of the process, but the implementation process will have to see whether or not supported. If the process has not been terminated, you can use the kill pid -SIGKILL , this time by the kernel to terminate the process, the process can not monitor this signal.

kill -19 PID: the equivalent of CTRL + Z, so that the process stop.

kill -9 PID: equivalent to kill the process.

***************************************************************************************************************************************

First, the background process management commands

FG, BG, Jobs, &, Ctrl + Z, Ctrl + C, Ctrl + \, Ctrl + D
. 1, &
applied to the end of a command, this command can be executed in the background, such as & gftp,
2, Ctrl + z
command being executed may be a foreground into the background, and in a suspended state, unenforceable
3, jobs
view the current number of commands run in the background
jobs -l option to display all tasks PID, jobs status can be running, He stopped, terminated, but if the task is terminated (kill), shell delete tasks from the current shell environment known list of process ID; that is, jobs command displays the current shell environment plays running in the background or a suspended task information;
4, fg
will command in the background adjusted foreground continue running
if there are multiple commands in the background, can be called up using the fg% jobnumber the selected command,% jobnumber is found by the jobs command number command being executed background (not pid)
5, BG
will be a pause command in the background, becomes proceed (in the background)
If more than one command in the background, you can use bg% jobnumber Number command to call up the selected command,% jobnumber is found in the background by the jobs command being executed (not pid).

The difference between five, ctrl + z (hang), ctrl + c (interrupt), ctrl + \ (quit) and ctrl + d (EOF) of

1, the performance of four operations

ctrl + c forced to interrupt the execution of the current program.
ctrl + z to interrupt the task, but the task does not end, he is still in the process, but in the background and maintain a suspended state. For it to continue running in the background, required "bg process ID" so that it continues to run; then "fg process number" may be the foreground of background processes.

ctrl + \ quit.

ctrl + d represents the end of the current input (i.e., the user no longer gives an instruction to the current program), then ends the current procedure usually Linux.

2, ctrl + c, ctrl + d, ctrl + z significance in linux.

the Linux:
Ctrl-C transmits SIGINT signal to all processes in the foreground process group. Often used to terminate the running program.
ctrl-z SIGTSTP transmits a signal to all processes in the foreground process group commonly employed to suspend a process.
ctrl-d is not a transmission signal, but rather a particular binary value indicates EOF.
ctrl- \ SIGQUIT send a signal to all processes in the foreground process group to terminate the foreground process and generates core file.

Key Function
Ctrl-c Kill foreground process
Ctrl-z Suspend foreground process
Ctrl-d Terminate input, or exit shell
Ctrl-s Suspend output
Ctrl-q Resume output
Ctrl-o Discard output
Ctrl-l Clear screen

 

Released nine original articles · won praise 1 · views 6691

Guess you like

Origin blog.csdn.net/u014426028/article/details/103324067