Using shell commands under Linux to control task jobs execution

Source: Internet
Author: User
Tags terminates

One, the following commands can be used to manipulate process tasks:

PS Lists the processes that are running in the system.

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

Jobs Lists the status of the tasks that are started in the current shell environment and displays all active task status information if jobsidis not specified, or if a task is reported to be terminated (that is, the status of the task is marked as Terminated ), theshell removes the process identity of the task 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).

Second, transfer the job to the background to run

If you often work under X graphics, you might have experienced the following: Running a GUI program with a terminal command, the GUI interface coming out, but your terminal still in place, you can't continue executing other commands in the shell unless you turn the GUI program off.

To enable the terminal to continue accepting commands after the execution of the program, you can move the process to the background and run the program using the following command:$xmms &(#假设要运行xmms, a program)

When this opens the xmms , the terminal prompts are back. Now Xmms is running in the background, but in case you forget to use "&" When you run the program and don't want to do it again, you can use "CTRL" + "Z" to suspend the program, and then tap the BG command. This keeps the program running in the background.

Iii. Concepts: Current Tasks

If there are 2 task numbers in the background, [1],[2]; If the first background task executes successfully and the second background task is still in progress, the current task will automatically become a background task for the background task number "[2]". So it can be concluded that the current task is subject to change. When the user enters commands such asFG,BG, andstop, the current task is changed if no quotation marks are added.

Iv. Inspection of Jobs

Use the jobs or PS command to view the jobs being executed.

The result of the jobs command execution,+ (plus sign) indicates that it is a current job,-(build number) represents a job after the current job, thejobs-l option shows the PID of all tasks, the status of jobs can be running, stopped, Terminated, but if the task is terminated (kill), The shell removes the process identity of the task from the list known to the current shell environment , that is, thejobs command shows the current shell environment The task information that is running in the background or is suspended.

V. the process hangs

1, the background process hangs:

Execute with the Stop command in Solaris (System) , view the job number (assuming num)through the jobs command, and then execute Stop%num.

In Redhat (System) , the Stop command does not exist, and the process can be suspended by executing the command kill-stop PID.

When you want to re-execute a task that is currently suspended, you can change the pending job status from stopped to runningthrough BG%num , still in the background, and when you need to perform in the foreground instead, Execute command FG%num .

2, the foreground process hangs:

"Ctrl" + "Z"

VI. termination of the process

1, the end of the background process:

Method One:

View the job number (assuming num) through the Jobs command, and then execute the kill%num.

Method Two:

Use the PS command to view the job's process number (pid, assumed to be pid), and then execute the kill PID.

2, the termination of the foreground process:

"Ctrl" + "C"

3. Other effects of Kill

In addition to terminating the process, kill can also send other signals to the process, using kill-l to see the signals that kill supports.

SIGTERM is the signal that kill sends without parameters, meaning that the process terminates, but execution depends on whether the process supports it. If the process is not terminated, the kill-sigkill pidcan be used, at which point the kernel terminates the process and the process cannot listen for this signal.

Above transfer from: http://blog.sina.com.cn/s/blog_673ee2b50100iywr.html

Using shell commands to control tasks under Linux jobs Execution (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.