develooper Front page | perl.beginners | Postings from December 2002

Re: Question: How do i start a program and get is pid ?

From:
Hannes Krueger
Date:
December 6, 2002 12:27
Subject:
Re: Question: How do i start a program and get is pid ?
Message ID:
200212052256.gB5Mumq7137890@alf.zfn.uni-bremen.de
>I want to start a program in perl but i need to keep
>the pid to be able to kill it in the future.
>
>For exmple:
>
>system("top &");
>
>this would start "top", but then i wouldn't be able to
>identify the process in order to kill it. Is there a
>way to do this (other than using fork) ?



Have you tried to use open?

$PID_OF_TOP = open (FILEHANDLE, "top |");

if you open a pipe to (or from) a process, open returns its PID. 
And you're able to get its output. (or write some data to its STDIN).

perldoc -f open


Hannes



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About