Linux monitors running shell scripts for a process

Source: Internet
Author: User

The script implements a 2-per-scan monitoring of the process for the specified process name and restarts once the discovery process does not exist.

#!/bin/sh

a=10;

While [[@a-gt 5]]; Do

if test $ (pgrep-f $1|wc-l)-eq 2;then

SH stop.sh

Gnome-terminal-x SH start.sh &

Fi

Sleep 2;

Done

Summary: (1) & indicates that the current process starts a process to execute the gnome-terminal command, (2) The parent process of Linux hangs up, the child process is not hung, but the parent process of the child process is set to 1 (init process), and (3) The command jobs-l to view the running process in the background; View the method Ps-ef|grep 20197 of the parent process for process 20197.

My question: pgrep-f $1|wc-l in SH and the result of running in the terminal is not the same, why do not exist in sh, is 2? , Welcome to comment discussion ~ ~

Linux monitors running shell scripts for a process

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.