Linux Job Management

Source: Internet
Author: User

1. Foreground work and background work(1) Concept
Foreground job: Start with terminal and Occupy terminal after startup. Background jobs: It is not related to the terminal at startup, or it is run in the background after the terminal is started (that is, releasing the terminal) without affecting the user to continue working in the terminal.
(2) How to transfer the foreground work to the backstage
A running job uses the Ctrl + Z key combination to move the command to the background and stop it, and a job that has not been started adds the "&" character directly after the command.

Note: The background job is sent to the background, but it is still related to the startup terminal of the program, if you exit the terminal, then this terminal's background work is also closed. You can use the Nohup command to achieve your goal if you want to send a job to the background out of the relationship to its startup terminal.

(3) Nobup command
The Nohup command can run the program in a way that ignores the pending signal, and the output information of the program being run will not be displayed to the terminal. If you use the Nohup command to submit a job, all output of the job is redirected to a file named Nohup.out by default (this file resides in the user's current working directory "echo $PWD") Of course we can also specify an output location for the Nohup command.
1) syntax
Nohup COMMAND [ARG] ...
2) Example
[[email protected] cron.hourly]# echo $PWD/etc/cron.hourly[[email protected] cron.hourly]# nohup ping 127.0.0.1 &[2] 4142[[email protected] cron.hourly]# nohup:ignoring input and appending output to ' nohup.out ' ^c[[email protected] Cron.ho urly]# Ls0anacron Nohup.out[[email protected] cron.hourly]# cat nohup.out PING 127.0.0.1 (127.0.0.1) (+) bytes of data . bytes from 127.0.0.1:icmp_seq=1 ttl=64 time=0.264 ms64 bytes from 127.0.0.1:icmp_seq=2 ttl=64 time=0.061 ms64 bytes From 127.0.0.1:icmp_seq=3 ttl=64 time=0.060 ms64 bytes from 127.0.0.1:icmp_seq=4 ttl=64 time=0.128 ms
(4) Jobs command
The jobs command is used to display the Task List and task status in Linux, including tasks that run in the background.
1) syntax
jobs [-LNPRS] [Jobspec ...]
2) options
-L: Shows the process number;-P: Displays the process number of the corresponding task only;-N: Shows the change of the task status;-R: The task that outputs only the running state (running);-S: Outputs only the Stop state (stoped) task.
3) Example

650) this.width=650; "src=" http://i.imgur.com/8q1ij5q.jpg "style=" border:0px; "/>

2. Related commands for job Management (1) FG command
Put background jobs (jobs that are running in the background or that are suspended in the background) and run at the foreground terminal. If there is only one in the background task, you can omit the task number when you use the command.
1) syntax
FG [JOB_SPEC]
2) Example

650) this.width=650; "src=" http://i.imgur.com/4eivAvG.jpg "style=" border:0px; "/>

(2) BG command
Put the job in the background to run it so that the foreground can perform other tasks. The effect of this command is the same as adding the symbol "&" after the instruction. You can also continue to run a task that has been stopped in the background.
1) syntax
BG [Job_spec ...]
2) Example

650) this.width=650; "src=" http://i.imgur.com/5zUdjqm.jpg "style=" border:0px; "/>

(3) Kill command
The KILL command is mainly used to terminate the daemon, the commonly used signals are: 1) SIGHUP: No need to close the process and let it reread Profile 2) SIGINT: Abort a running process; equivalent to CTRL+C9) SIGKILL: Kill a running Process 15) SIGTERM: Terminate a running process Sigcont: Let background jobs continue to run) SIGSTOP: Put jobs in the background hibernate

650) this.width=650; "src=" http://i.imgur.com/e7eUnhH.jpg "style=" border:0px; "/>

3, set the priority of the process

The higher the priority of the process, the more the program is executed first. The default value range for the system is 100 to 139, and the smaller the value the higher the priority. However, there is a command in the system to adjust the process priority, known as the Nice (command) value, the range is 20 to 19, and the lower the value the higher the priority, therefore, the priority of the process = Process priority (old) +nice value. For example, process A has a system priority value of 115, and process B has a system priority of 120, it is clear that process A has a higher priority than process B, but we can adjust the nice value of process B to 10, when the priority of the process becomes 110, and the CPU executes first.

(1) Nice command
Applies to processes that are not started
1) syntax
Nice [OPTION] [COMMAND [ARG] ...] -N: Specify a priority value
2) Example
[[email protected] testdir]# ./test.sh &[1] 4975[[email protected]  testdir]# nice -n -10 ./test.sh &[2] 4983[[email protected]  testdir]# ps -lf s   uid    pid   ppid   C PRI  NI ADDR SZ WCHAN  TTY           TIME CMD4 S     0   4757    4753  0  80   0 - 27121 wait   pts/2     00:00:00 bash0 T     0   4975    4757  0  80   0 - 26527 signal pts/2     00:00:00 test.sh4 T     0   4983    4757  0&Nbsp; 70 -10 - 26527 signal pts/2    00:00:00 test.sh4  r     0   4984   4757  0  80    0 - 27035 -      pts/2     00:00:00 ps[2]+  stopped                  nice -n -10 ./test.sh
(2) Renice command
Applies to processes that are already running
1) syntax
Renice [-N] Priority [[-P] pid ...] [[-G] pgrp ...] [[-u] user ...]
2) options
-N: Specifies the priority progression value-G: Specifies the process group id;-p< Program identification code;: Changes the priority level of the program, which is a preset value. -U: Specifies the user name of the open process.
3) Example

650) this.width=650; "src=" http://i.imgur.com/6Q66yIN.jpg "style=" border:0px; "/>


This article is from the "Learn Linux for Beginners" blog, please make sure to keep this source http://kop309.blog.51cto.com/9034739/1850969

Linux Job Management

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.