in reply to Obtain the child process id in perl

With system I think you can't.

Before the call to system the programm doesn't run yet, and the future PID unpredictable. After it is already finished, and the old PID useless.

And why do you want that anyway? Looks like an XY Problem to me.

And why would you spawn an ls process when you have opendir and readdir as well as glob or File::Find?

Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: Obtain the child process id in perl
by Anonymous Monk on May 26, 2010 at 10:14 UTC

    For an example I used ls command there.

    My actual process is that,

    Server is keeping on running in one side. This server will execute another application which might be executed at min 10 minutes to get the data from the database or file. The application will create a file in common directory once the data is get from the file or database.

    Server will continue to do further process. It will not wait for any child process. It just checks file is available in the common directory.

    Here when the application is not written the file at that time I need to kill the process with the process id.

    For this how do I get the process id of the child process?

      You fork, and store the child PID in the parent. In the child you exec the application you want to run.

      Or you use IPC::Run, which abstracts such things away.

      See also: perlipc

      Perl 6 - links to (nearly) everything that is Perl 6.

        I have used the following code

        my $pid = fork; unless($pid){ exec('script 2>output.log'); } print "Child Process Id:$pid\n";

        In the above example got the process id of the child process but not the process which is executed the command

        How can I take the process id of the process which is running the actual application?