Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   Killing processes (http://www.velocityreviews.com/forums/t285313-killing-processes.html)

hepp 08-30-2004 07:45 PM

Killing processes
 
I need to execute a system command, read the printouts from its output
stream and be able to kill the process when needed. Is there any way
to accomplish all this in C/C++?

First I tried to use popen to open a pipe to the process, but then I
can't kill it since it doesn't return the pid. The only thing I can do
is to close the output stream by using pclose, but it waits for the
process to finish so it's of no use.

One possible way to do it is to use popen to get access to the output
stream and then use system commands to find out its pid, but there got
to be a better way, doesn't it?

Victor Bazarov 08-30-2004 07:57 PM

Re: Killing processes
 
hepp wrote:
> I need to execute a system command, read the printouts from its output
> stream and be able to kill the process when needed. Is there any way
> to accomplish all this in C/C++?


No, but you can accomplish the first step by calling the 'system'
function. All other steps can be done using OS-specific means.

> First I tried to use popen to open a pipe to the process, but then I
> can't kill it since it doesn't return the pid. The only thing I can do
> is to close the output stream by using pclose, but it waits for the
> process to finish so it's of no use.
>
> One possible way to do it is to use popen to get access to the output
> stream and then use system commands to find out its pid, but there got
> to be a better way, doesn't it?


The better way is to use platform-specific functions to control processes.
However, they are OT here. Ask in a newsgroup for your platform/OS.

V


All times are GMT. The time now is 10:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.