LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 03-02-2005, 06:23 PM   #1
sumbabs
LQ Newbie
 
Registered: Mar 2005
Posts: 1

Rep: Reputation: 0
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
 
Old 03-03-2005, 10:38 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PID Kill Script or command ? Webmin rapture_1 Linux - General 1 11-02-2005 11:11 AM
Help with System() command on linux PERL I R J Programming 2 01-05-2005 12:20 PM
Converting a Windows Perl script to a Linux Perl script. rubbercash Programming 2 07-19-2004 10:22 AM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM
newgrp command within perl/csh script bobsey Programming 1 04-13-2001 10:05 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration