Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

process monitoring script

by xtremenet (Initiate)
on Apr 14, 2018 at 16:42 UTC ( [id://1212878]=perlquestion: print w/replies, xml ) Need Help??

xtremenet has asked for the wisdom of the Perl Monks concerning the following question:

hello there, can anyone help me making a scrip please?

my assignment is to write a script to monitor a process.

it is checking a process for every 30 sec,

and whenever the process is gone (or done closing) then restart it again.

I am so bad at coding yet i try to study it.. please help me : )

Replies are listed 'Best First'.
Re: process monitoring script
by AnomalousMonk (Archbishop) on Apr 14, 2018 at 17:04 UTC

    Further to marto's reply:   As a basic introduction, see perlintro. Also see the articles in the Getting Started with Perl and Getting Deeper Into Perl sections of the monastery's Tutorials wing. My first thought would be something along the lines of

    while (1) { while (process_is_still_going()) { sleep 30; } restart_the_process(); }
    (Note that the infinite  while (1) { ... } loop has no way to ever end the program.) See Compound Statements in perlsyn for info on while-loops. See sleep. This loop calls subroutines; see perlsub.

    Please try to come up with some code. The closer it is to something we can play with too, the better; see Short, Self-Contained, Correct Example. When you have some code about which you still have questions, please come back and we'll see if we can answer those questions.


    Give a man a fish:  <%-{-{-{-<

Re: process monitoring script
by marto (Cardinal) on Apr 14, 2018 at 16:56 UTC
Re: process monitoring script
by karlgoethebier (Abbot) on Apr 16, 2018 at 08:58 UTC

    You need to take a look at your process table (untested):

    #!/usr/bin/env perl use strict; use warnings; use Proc::ProcessTable; use feature qw(say); say grep {/emacs/i} map { $_->cmndline } @{ Proc::ProcessTable->new->table }; __END__

    See also Proc::ProcessTable and Better way to search in the process table?.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: process monitoring script
by Anonymous Monk on Apr 16, 2018 at 04:30 UTC
    First question – is this a homework assignment? If so, ask your instructor first. If it is a work assignment and e.g. you are a new-hire or fairly new at this ... ask a co-worker or your manager. If you want us to offer meaningful guidance, we need to know a lot more about your actual scenario.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1212878]
Approved by NetWallah
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found