Linux monitors the running shell scripts of a process

Source: Internet
Author: User

Linux monitors the running shell scripts of a process

This script scans and monitors the process with the specified process name at intervals of 2. Once the process does not exist, it restarts.

#! /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;

Conclusion: (1) & indicates that the current process starts another process to execute the gnome-terminal command; (2) if the parent process in linux crashes, the child process does not, instead, set the parent process of the child process to 1 (init process); (3) view the command jobs-l of the background running process; view the method of the parent process of process 20197, ps-ef | grep 20197.

My problem: pgrep-f $1 | the running status of wc-l in sh is different from that in the terminal. Why does the execution in sh not exist, is it 2 ?, Welcome to comments and discussions ~~

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.