Work Management job control Quick start for Linux

Source: Internet
Author: User

Learn Linux easily:


Job control is to allow Linux to perform multiple tasks in a bash, which is actually the work of multiple sub-processes in bash.

This is a question? is Linux not bringing 7 terminal Windows? Do you have a few more jobs in this area?

Yes, you can.

Alt1-6 is a six command-line terminal that can switch to each other

Alt+7 graphical interface terminal, (ctrl+alt+f1 back to Linux command line terminal)


The problem: In some of the security more rigorous companies, will limit the number of users login connections (/etc/security/limits.conf) set, the user can only connect a number of connections, at this time the job control is effective,!


Job control is divided into foreground foregroud and backstage background


Example:


# tar-zpcf/tmp/etc.tar.gz/etc &[1] 8400 <== [job number] PID # tar:removing leading '/' from member names # in The number in brackets is the work number, which is related to bash control. # The next 8400 is the PID that works in the system. As the subsequent data flow is the tar run, # because we do not add data flow redirection, it will affect the screen! But it will not affect the operation of the foreground Oh!


[[email protected] ~]# tar-zcvf/tmp/etc.tar.gz/etc >/tmp/log.txt 2>&1 &[1] 8429[[email protected] ~]#

Oh! As a result, the output of the information sent to him to/tmp/log.txt, of course, will not affect our prospects of the work. That said, you should be more aware of the importance of data flow redirection! ^_^
[[email protected] ~]# jobs [-LRS] options and Parameters:-L: In addition to listing the job number and command string, the PID numbers are listed at the same time;-R: Lists only the work that is running on the background;-S: Lists only the pauses in the background (ST OP) work. Example one: Observe the current bash, all work, with the corresponding Pid[[email protected] ~]# jobs-l[1]-10314 Stopped vim ~/.bashrc[2]+ 10833 S Topped Find/-print
Call the working FG Fg+number in the background to


Jobs See how much work is currently

FG%number The background work to the foreground

VI Log.txt

CTRL + Z will be put back in the background, but the status is stop

BG%number Let the background stop work in the background into running state


Managing the work behind the scenes Kill-singal

Singal:

1 Read the configuration file again

2 Equals CTRL + C

9 forced termination such as VI log.txt A. SWP file is generated after a forced termination

15 Normal termination


Kill can be followed by PID can also be with the work management default is PID so we have to manage job control when it is best

Is Kill-? %number



& After the background execution but you exit the terminal the script execution will also stop

Example:

Vim sleep.sh

#!/bin/bash

/bin/sleep 500s

/bin/echo "I have sleept 500s"


#chmod +x sleep.sh


The Nohup command allows work in the background to run after the terminal exits and logs on again


Nohup./sleep.sh >/test/log.txt 2>&1 &

# exit


Jobs is no longer available after re-login

Ps-ef |grep sleep View related processes still in



PS Usage:


-e Displays all processes.

-F full format.

-H does not display the caption.

-L long format.

-W wide output.

A shows all processes on the terminal, including the processes of other users.

R displays only the processes that are running.


U Displays the status of the program in a user-oriented format.


X shows all programs and does not differentiate them by terminal.


Used in

Ps-l

Ps-ef

Ps-aux



























This article from "Kobebryant" blog, declined reprint!

Work Management job control Quick start for Linux

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.