Linux monitors the running shell scripts of a process and linux monitors shell scripts.

Source: Internet
Author: User

Linux monitors the running shell scripts of a process and linux monitors shell scripts.

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 ~~


Write a program in linux to check whether a process exists. You cannot use shell scripts.

You can use pipelines or something, if. you wrote out, in. create a new pipe in out. When it starts, send a message to let B. when receiving the message from this pipeline, it means that a is started. If a. out is not written by you, then I will not, ha, hope to help you. New to LINUX

Which of the following is a shell script used in linux to monitor whether multiple processes are dead and kill and restart if they die?

I use the process that monitors a process: the "vmstat" command as an example.

#! /Bin/bash
PROSS = 'ps-el | grep vmstat | awk '{print $14 }''
STAT = 'ps-el | grep vmstat | awk '{print $2 }''
PID = 'ps-el | grep vmstat | awk '{print $4 }''

If [$ PROSS]
Then
If [$ STAT = "Z"]
Then
Echo "$ PROSS has dead"
Echo "Now, killing it"
Kill-9 $ PID
Echo "Now, restart"
Vmstat 2 5>/tmp/vmstat.txt &
Else
Echo "$ PROSS is running healthy"
Fi
Else
Echo "The programm has dropped"
Echo "Now, restart"
Vmstat 2 5>/tmp/vmstat.txt &
Fi

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.