Shell script background Run operation

Source: Internet
Author: User

Recently help students write a simple script = = (do not spray me ~), the situation frequency, the background operation and the concept of CTRL + Z did not understand clearly made a big joke, the script and the resolution process:

#!/bin/bash while:;d o a= ' date +%y/%m%d%t ' java= ' ps aux |grep vsftpd |awk ' nr==1{print $} ' echo "Time $A,CPU usage $java" >> xiangchen/1.txt sleep Done

At that time directly using CTRL + Z thought is directly in the background to run, later learned to just suspend the foreground task, hang and no background run, hehe--
Later Baidu a bit to find a solution is to put the running task Ctrl + Z suspend suspend:
# SH vsftpd.sh &
# [1] 1159
# jobs-l
# [1]+ 1159 Running./vsftpd.sh &//view running in the background
# $ disown-h%1
# $ PS-EF | grep vsftpd
# root 1492 1143 0 15:42 pts/0 00:00:00/bin/bash./vsftpd.sh
# root 1531 1143 0 15:43 pts/0 00:00:00 grep vsftpd
Here we can let the program end +& hang, and then use the Disown-h% program number to let it run in the background, not affected by the current shell exit. There is also a way to do the same with this effect:
# (./vsftpd.sh &)
# [1]+ killed./vsftpd.sh
# Ps-ef |grep vsftpd
# root 1578 1 0 15:50? 00:00:00/bin/bash./vsftpd.sh
# root 1699 1615 0 15:52 pts/2 00:00:00 grep vsftpd
End script Process: kill-9 process number
[Email protected] ~]# kill-9 1578
[Email protected] ~]# Ps-ef |grep vsftpd
Root 1708 1615 0 15:55 pts/2 00:00:00 grep vsftpd
When the system is running, the script is written to the boot configuration file.


Keep track of what you think about every day.

This article is from the "Linux Nest" blog, please be sure to keep this source http://xiangcc.blog.51cto.com/10201823/1649634

Shell script background Run operation

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.