I have an application here that launches a process via the "popen()"
command.

For anyone unfamiliar popen()  works as follows:

            FILE *fp;   /* a FILE pointer */
              ...
            fp = popen(command, "r");

Where "command" is any common Unix command that can be run from the
shell written as it would be if run from the command line. For
example, "command" could be:
             char *command = "ls -l";
or anything that could be run in that manner. The "r" is the mode
which in this case specifies that the pipe will be used for reading.
What "popen()" essentially does is it opens a pipe, forks a new
(child) process and launches the command specified by "command". The
output of the command is then sent down the pipe and can be read in
the parent via the file pointer "fp" using something like "fread()".

Now here's the main question. The processed launched via "popen()"
from the parent process runs over a period of time. Is there a simple
way to kill the process that was started via "popen()" from the parent
process? I considered the possibility of sending a signal from the
parent to the process launched by popen() using  the "kill()" function
but "kill()" requires  knowledge of the pid of the process to which I
want the signal to be sent. Unfortunately "popen()" returns a file
pointer but nowhere does it return the pid of the process that was
started.

Thus the  question boils down to, is there a simple way for the parent
process to get the pid of the process that it stared via "popen()" so
that it could thereby send signals to it?  and/or is there a simple
way in which the parent can kill such a process? Perhaps there is but
I am just overlooking it.

or...

Would it make more sense to change the whole manner in which the
process is being started, for example, instead of using "popen()",
should I manually create a pipe via pipe(), fork a new process via
"fork()" and then replacing the child process with the desired command
using "exec()" and simply redirect the file descriptors so that
standard output from the desired command is sent down the pipe and can
thereby be read via a low level "read()"??

Any suggestions would be appreciated.

Thank You.

/John <[EMAIL PROTECTED]>



-- 
email: [EMAIL PROTECTED]
Local mailserver <landreau.ruffe.edu> , remote <ns.computer.net>
--------
Linx:
http://www.computer.net/
http://einval.vol.8m.com/

Yeah!!! Look at him run that ball down!!!
begin:vcard 
n:Holotko;John
x-mozilla-html:FALSE
org:MicroService Co.
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Programmer
note:Phone: (914)-779-3966
x-mozilla-cpt:;5088
fn:John Holotko
end:vcard

Reply via email to