Common commands for managing jobs in Linux

Source: Internet
Author: User

Common commands for managing jobs in Linux

1 put the command or script in the background to run

#命令 &

eg

RPM-IVH zlib**.rpm &

./run.sh &


2 pausing a command to the background

CTRL + Z


3 Viewing background commands

#jobs

Parameters:

-L: The PID is listed in addition to the job number listed

-r: Lists jobs running only in the background (run)

-S: Lists only paused jobs


4 put a suspended job in the background processing BG

CTRL + Z put your homework into the background first

#bg job_id implementation to move the job to the background


5 Set up the background job to the foreground process FG

#fg job_id


6 using Kill to send a signal to operate jobs

Kill-signal%job_id here must add%, otherwise there will be surprise, hey

Parameters:

-L lists the signals that the current kill can use

Signal: Indicates to the background of the job what instructions, with man 7 signal know

-1 (number): Re-read the parameter settings file (similar to reload)

-2: Represents the same action as the keyboard input ctrl-c

-9: Force deletion of a job immediately

-15: Terminate a job in the normal way. Not the same as 9.



Demonstrate:

amp1:~ # cat jobs.sh   # #jobs脚本, input time every two seconds to jobs.txt #!/bin/bashwhile :d o  sleep 2time= ' date + "%h-%m-%s" echo  "this time is   $time"  > > jobs.txtdoneamp1:~ # ./jobs.sh &    # #放到后台运行 [1] 50770You  have new mail in /var/mail/rootamp1:~ # amp1:~ # jobs    # #查看作业 [1]+  running                  ./jobs.sh &amp1:~ # fg 1      # #调用到前台运行./jobs.sh^z         # #ctrl +z  Call Pause [1]+   Stopped                  ./jobs.shamp1:~ # watch cat jobs.txt  # #动态显示jobs. txt Write status This time  is  20-10-49this time is  20-10-51this time is  20-10-53this time is   20-10-55this time is  20-10-57this time is  20-10-59this  time is  20-11-01this time is  20-11-03this time is   20-11-05this time is  20-11-07this time is  20-11-09this time  is  20-11-11this time is  20-11-13this time is   20-11-15   # #看这个时间, Now is the paused state------------------------------------------------------------------amp1:~ # bg 1     # #调用暂停作业, run in the background [1]+ ./jobs.sh &you have new mail in / var/mail/rootamp1:~ # jobs   # #jobs运行状态 [1]+  running                  ./jobs.sh &amp1:~  #  then the upper Amp1:~ # watch cat jobs.txtthis time is  20-10-49this  time is  20-10-51this time is  20-10-53this time is   20-10-55this time is  20-10-57this time is  20-10-59this  time is  20-11-01this time is  20-11-03this time is   20-11-05this time is  20-11-07this time is  20-11-09this time  is  20-11-11this time is  20-11-13this time is   20-11-15this time is  20-18-00  //here has been suspended for 7 minutes and then started again, stating that the BG command took effect this time  is  20-18-02this time is  20-18-04this time is   20-18-06this time is  20-18-08this time is  20-18-10this time  is  20-18-12amp1:~ # kill -9 %1   #成功的杀死jobsamp1: ~ # kill -9 %1-bash: kill: % 1: no such jobyou have new mail in /var/mail/rootamp1:~ #  Jobsamp1:~ # jobs









This article is from the "Tiandaochouqin" blog, make sure to keep this source http://luzhi1024.blog.51cto.com/8845546/1651727

Common commands for managing jobs in Linux

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.