Getting PID from system?
am 15.09.2004 19:01:49 von Michael W Cocke
Is there a better way to get the result PID from a 'system' command
than grepping the output of ps?
Mike-
--
If you can keep your head while those around you are losing theirs...
You may have a great career as a network administrator ahead!
--
Please note - Due to the intense volume of spam, we have installed
site-wide spam filters at catherders.com. If email from you bounces,
try non-HTML, non-encoded, non-attachments,
Re: Getting PID from system?
am 15.09.2004 20:02:40 von Gunnar Hjalmarsson
Michael W Cocke wrote:
> Is there a better way to get the result PID from a 'system' command
> than grepping the output of ps?
Yes. See "perldoc perlvar".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Getting PID from system?
am 16.09.2004 14:42:25 von Michael W Cocke
On Wed, 15 Sep 2004 20:02:40 +0200, Gunnar Hjalmarsson
wrote:
>Michael W Cocke wrote:
>> Is there a better way to get the result PID from a 'system' command
>> than grepping the output of ps?
>
>Yes. See "perldoc perlvar".
I'm stupid today - all I see that might be applicable is $child_error,
but that returns the status, not the pid. What am I missing?
Mike-
--
If you can keep your head while those around you are losing theirs...
You may have a great career as a network administrator ahead!
--
Please note - Due to the intense volume of spam, we have installed
site-wide spam filters at catherders.com. If email from you bounces,
try non-HTML, non-encoded, non-attachments,
Re: Getting PID from system?
am 16.09.2004 15:02:32 von Gunnar Hjalmarsson
Michael W Cocke wrote:
> Gunnar Hjalmarsson wrote:
>> Michael W Cocke wrote:
>>> Is there a better way to get the result PID from a 'system'
>>> command than grepping the output of ps?
>>
>> Yes. See "perldoc perlvar".
>
> I'm stupid today - all I see that might be applicable is
> $child_error, but that returns the status, not the pid. What am I
> missing?
$$ (aka $PID)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Getting PID from system?
am 16.09.2004 17:25:18 von Michael W Cocke
On Thu, 16 Sep 2004 15:02:32 +0200, Gunnar Hjalmarsson
wrote:
>Michael W Cocke wrote:
>> Gunnar Hjalmarsson wrote:
>>> Michael W Cocke wrote:
>>>> Is there a better way to get the result PID from a 'system'
>>>> command than grepping the output of ps?
>>>
>>> Yes. See "perldoc perlvar".
>>
>> I'm stupid today - all I see that might be applicable is
>> $child_error, but that returns the status, not the pid. What am I
>> missing?
>
>$$ (aka $PID)
My perlvar shows that as:
The process number of the Perl running this
script. You should consider this variable
read?only, although it will be altered across
fork() calls. (Mnemonic: same as shells.)
I'm looking for the PID of the command I just started with a
'system &'
The problem I run into with ps|grep is that if the program is running
already, it gets ugly... and as I write this, I see a way to handle
that. !
Nevermind, thanks anyway.
Mike-
--
If you can keep your head while those around you are losing theirs...
You may have a great career as a network administrator ahead!
--
Please note - Due to the intense volume of spam, we have installed
site-wide spam filters at catherders.com. If email from you bounces,
try non-HTML, non-encoded, non-attachments,
Re: Getting PID from system?
am 16.09.2004 23:22:46 von Gunnar Hjalmarsson
Michael W Cocke wrote:
> I'm looking for the PID of the command I just started with a
> 'system &'
Ouch, I'd better read the question before trying to answer it. My
apologies!
> The problem I run into with ps|grep is that if the program is
> running already, it gets ugly... and as I write this, I see a way
> to handle that. !
Would it be an option for you to start the subprocess via a pipe from
open() instead of via system()? From "perldoc -f open": "If the open
involved a pipe, the return value happens to be the pid of the
subprocess."
Haven't tried it, but that's all I can think of.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: Getting PID from system?
am 17.09.2004 16:18:58 von Michael W Cocke
On Thu, 16 Sep 2004 23:22:46 +0200, Gunnar Hjalmarsson
wrote:
>Michael W Cocke wrote:
>> I'm looking for the PID of the command I just started with a
>> 'system &'
>
>Ouch, I'd better read the question before trying to answer it. My
>apologies!
>
>> The problem I run into with ps|grep is that if the program is
>> running already, it gets ugly... and as I write this, I see a way
>> to handle that. !
>
>Would it be an option for you to start the subprocess via a pipe from
>open() instead of via system()? From "perldoc -f open": "If the open
>involved a pipe, the return value happens to be the pid of the
>subprocess."
>
>Haven't tried it, but that's all I can think of.
Unfortunately not. The app I need to start from the system is on the
odd side, and I need to start it in a very specific way. No matter
though, I realized that the correct way to solve my problem has
nothing to do with how I start the detached app.
See, what was happening was if the detatched app was already running
from a previous session, the new session would just start another, and
then the ps|grep would grab the PID of the first copy of the app, not
the correct copy.
The CORRECT solution is for me to check for an already running copy of
the app before I do anything else.
I'm slow, but I get there eventually.
Mike-
--
If you can keep your head while those around you are losing theirs...
You may have a great career as a network administrator ahead!
--
Please note - Due to the intense volume of spam, we have installed
site-wide spam filters at catherders.com. If email from you bounces,
try non-HTML, non-encoded, non-attachments,
Re: Getting PID from system?
am 18.09.2004 02:20:43 von Jim Gibson
In article , Michael W
Cocke wrote:
> On Thu, 16 Sep 2004 23:22:46 +0200, Gunnar Hjalmarsson
> wrote:
>
> >Michael W Cocke wrote:
> >> I'm looking for the PID of the command I just started with a
> >> 'system &'
> >
> >Ouch, I'd better read the question before trying to answer it. My
> >apologies!
> >
> >> The problem I run into with ps|grep is that if the program is
> >> running already, it gets ugly... and as I write this, I see a way
> >> to handle that. !
> >
> >Would it be an option for you to start the subprocess via a pipe from
> >open() instead of via system()? From "perldoc -f open": "If the open
> >involved a pipe, the return value happens to be the pid of the
> >subprocess."
> >
> >Haven't tried it, but that's all I can think of.
>
> Unfortunately not. The app I need to start from the system is on the
> odd side, and I need to start it in a very specific way. No matter
> though, I realized that the correct way to solve my problem has
> nothing to do with how I start the detached app.
Then you might try using fork to start a new process and exec to start
your app. The fork will return the PID of the child process, and the
exec will replace your perl process with your app using the same PID.