Redirecting the PID
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Redirecting the PID




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Redirecting the PID  
Dennis


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-23-04 03:36 PM

Hi,
I'm attempting to build a pmfl type interface to manage some
processes.  Such as monitoring their status, and having the option to
kill/restart them.  I'm looking for a generic way to capture the PID
of each process that I'm running.  Normally I would do something like:

system("sh -ic \"((program_executable > Debug &) 2>&1) >
/tmp/PID\" > /dev/null 2>&1");

This would redirect the debug output to a file called 'Debug' and
redirect the pid to a file called 'PID', which I can then read in.

However, now I want to be able to run the program inside an xterm so
that I can see the debug in realtime.  Something like:

system("sh -ic \"xterm +wf -hold -e program_executable &\">
/dev/null 2>&1 > /tmp/PID");

The problem with this setup is that I successfully retrieve the pid
for the xterm, but I've been unable to get the pid for the
program_executable.

Does anyone have any ideas on how I might modify the above to return
BOTH the xterm PID to a file and the program_executable PID to another
file?  Or perhaps you can think of a better way to get access to this
info.  I thought of doing some "ps -ef | grep" type command to get the
PID, but thought I might run into some problems if I had multiple
processes running with the same name.

Thanks in advance for all of your ideas!

Dennis





[ Post a follow-up to this message ]



    Re: Redirecting the PID  
Fletcher Glenn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-23-04 04:39 PM



Dennis wrote:
> Hi,
>   I'm attempting to build a pmfl type interface to manage some
> processes.  Such as monitoring their status, and having the option to
> kill/restart them.  I'm looking for a generic way to capture the PID
> of each process that I'm running.  Normally I would do something like:
>
>        system("sh -ic \"((program_executable > Debug &) 2>&1) >
> /tmp/PID\" > /dev/null 2>&1");
>
> This would redirect the debug output to a file called 'Debug' and
> redirect the pid to a file called 'PID', which I can then read in.
>
> However, now I want to be able to run the program inside an xterm so
> that I can see the debug in realtime.  Something like:
>
>        system("sh -ic \"xterm +wf -hold -e program_executable &\">
> /dev/null 2>&1 > /tmp/PID");
>
> The problem with this setup is that I successfully retrieve the pid
> for the xterm, but I've been unable to get the pid for the
> program_executable.
>
> Does anyone have any ideas on how I might modify the above to return
> BOTH the xterm PID to a file and the program_executable PID to another
> file?  Or perhaps you can think of a better way to get access to this
> info.  I thought of doing some "ps -ef | grep" type command to get the
> PID, but thought I might run into some problems if I had multiple
> processes running with the same name.
>
> Thanks in advance for all of your ideas!
>
> Dennis

For capturing program output directly, look at the command popen().
However, you cannot know the pid of a program run under the system()
command because when system returns, the program has already completed
execution.  Probably the best alternative is to fork() and exec() the
program yourself, and create a pipe() connected to the program's stdin
and stdout yourself.  This is how a shell program does this.

--

Fletcher Glenn






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 08:30 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register