Re: check if another process on my perl program is running

From: Dave Sisk (dsisk_at_nc.rr.com.0nospam0)
Date: 03/05/04


Date: Fri, 05 Mar 2004 05:04:52 GMT

You can probably do a backtick ps -ef | grep your_script_name or something
similar. For instance, if you your script is "onlyone.pl", then you should
be able to do something like this in the script:

$rv = `ps -ef | grep onlyone.pl`;
if ($rv == onlyone.pl) die;

"Erik" <elremovethis@thistoolinux.nu> wrote in message
news:piM1c.51209$mU6.208771@newsb.telia.net...
> Pierre-Yves wrote:
> >
> >
> > Thanks Erik!
> > I'm working with a flag file now and I would like to get rid of this
because
> > as you said when the script exits on an unexpected error, then the
> > intervention of an operator is required to delete the flag file... It
> > doesn't happen very often but during the last 3 weeks it happened 2
times
> > and it's blocking our business...
> > That's why I thought about something like checking the running
processes...
>
> Aha, I see!
> In an hack I did some time ago I "solved" the problem with the flagfile
> with an even dirtier hack...
> I made a sub called "SafeExit" or something, in that sub I closed and
> deleted my flagfile and finally made a "die".
>
> As I said, not very nice... But it worked...
> This program was a batchprogram so I could just (almost) ignore the fact
> that someone pressed ctrl-c or klicked the upper right corner.
>
> If you find any good solution, please post it. Maby I'll change that old
> hack to make it more clean. :-)
>
> ./Erik
>



Relevant Pages

  • Re: Find a line in a text file then print a field
    ... Here is "grep" part of my perl script so far (ommitting the various ... the matching lines in an array. ...
    (perl.beginners)
  • Re: [PATCH] kconfig: simplification of scripts/extract-ikconfig
    ... I found a way to work around the differences in behavior of grep. ... I've rewritten the extract-ikconfig script to extract the kernel ... -# GNU General Public License for more details. ...
    (Linux-Kernel)
  • Re: I need a custom script to extract data from my web logs.
    ... >> You aren't passing anything to awk and you don't need awk anyway. ... My original script was using awk to output the data by ... > piping the output of the original grep through awk to the printf. ... (i.e. searchlogs log???? ...
    (comp.unix.shell)
  • Re: Standard output piping problem
    ... >> Why won't the multiple pipes present output? ... Barry in his reply suggested that it's a buffering issue and to test ... this I let the script run for a few minutes. ... Truth be told I was going to use grep as it was simpler than working out how ...
    (comp.unix.shell)
  • Re: [PATCH] kconfig: simplification of scripts/extract-ikconfig
    ... The version of grep on the machines I tested on does ... modified the script to use perl instead. ... I've rewritten the extract-ikconfig script to extract the kernel ... -# GNU General Public License for more details. ...
    (Linux-Kernel)