Wonderful Linux background tasks

Source: Internet
Author: User
Wonderful Linux background task-Linux Enterprise Application-Linux server application information. The following is a detailed description. Linux, as a multi-task environment, allows users to execute multiple tasks at the same time, such as viewing system conditions, backing up data, editing files, and printing files.

A time-consuming task should not be executed in the foreground task, but should be handed over to the background task for execution. In this way, the foreground task can continue to operate normally without waiting. Example:

# Find/-name testing &
# Fg
If you want to convert the task in the preceding example to background execution, use "&". However, because the program is executed in the background, the output of the program will not appear on the screen. How do you manage multiple tasks in the background when they are executed? How do I know the execution of background tasks? How can I terminate or temporarily stop the execution of background tasks? Next we will illustrate it one by one.

Control Management

Example:
# Du-a/user> user. data &
[1] 237
# Find/-name core-type f-ls> core. data &
[2] 238
Run the "&" command to put the three tasks in the background for execution. Run the "jobs-l" command to display the execution of background tasks, for example:
# Jobs-l
[1] + 237 Running du-a/user> user. data
[2]-238 Running find/-name core-type f-ls> core. data

First, we will introduce a special term of task control: current task. The preceding task is "du-a/user> user. data", because the background task number is "[1]". If the first background task is successfully executed and the second background task is still in progress, the current task automatically becomes a background task with the background task number [2. So we can conclude that the current task will change. When you enter commands such as "fg", "bg", and "stop", if no quotation marks are added, all changes are made to the current task.

Terminate background tasks
Commands always encounter errors. In this case, you can use the built-in Shell command "kill" to end the task. To end the background task "du-a/user> user. data", run the following command:
# Killed 237
# Kill % 1
237 indicates the PID Number of the first background task. To terminate the second background task, either of the following methods can be used:
Method 1: # kill % 2
Method 2: # kill %-

Pause a task
The built-in Shell command "stop" can be used to pause background tasks. Example:
Stop % (stop the execution of the first background task)
Stop % n (stop the execution of the n background tasks)
After understanding how to use the "stop" command, you can pause the execution of background tasks that you want to stop. For example, if you want to organize an annual report using the "nroff" command, you can place it in the background for execution because of the large file volume. The command is as follows:
# Nroff-ms moonth [1-12]. acct> year2003.acct &
[4] 240
When the command is half processed, it is found that the moonth12.acct file is old and needs to be updated. Then, run the "jobs" command to check that the background task "[4]" is still being executed, however, you cannot know the month to which the command has been processed. Enter the following command to pause the execution of the background task "[4:
# Stop % 4
Then, check the end Of the year2003.acct file to see if it has been processed until January 1, December. If not, update the data in the moonth12.acct file, and run the "bg" command to "[4]" The background task that has been temporarily stopped. This not only can correct the error file, but also does not need to re-execute the processed task.

Convenience
Foreground and background tasks can indeed facilitate daily operations. Because we will certainly encounter multiple operations at the same time in daily operations. If you do not use foreground or background tasks at this time, it will take a lot of time. Proficient in front-end and back-end tasks to achieve "Hour" and "Half Hour.

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.