LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Getting PID from a system command in Linux perl script (https://www.linuxquestions.org/questions/linux-general-1/getting-pid-from-a-system-command-in-linux-perl-script-296901/)

sumbabs 03-02-2005 06:23 PM

Getting PID from a system command in Linux perl script
 
Hi,


I spawn a task on a remote machine using a 'system' command from a perl script as follows,

system("ssh <remote machine name> "<my command>&");

Note that I want to start a background task on the remote machine.

Now I would like to know the PID of the task I just launched on the remote machine. I could do the following to get the PIDs of all the tasks and then maybe do a grep.

system("ssh <remote machine name> ps");

But the problem is that I can have multiple tasks by the same name. Makes things messy/not reliable that way.

Is there a way that ssh can return me the PID of the spawned task?

Thanks
Sum

Technoslave 03-03-2005 10:38 AM

No, I don't think there is an easy way to do it.

You might try something like this:

ssh -f remote "command; echo $$"

The -f obviates the need to use &, the only problem is, and I haven't done anything more than to make sure it returns something. The echo $$ probably isn't giving you back the commands PID, it's probably giving back something else.

However, it's a possible way to help in dealing with the messy nature of the script.

The other way to do it is in your script that you run, you can have it echo out it's PID to a file in /tmp and grab it that way instead of doing a `ps` on the machine.


All times are GMT -5. The time now is 10:38 AM.