Killing processes

Discussion in 'C++' started by hepp, Aug 30, 2004.

  1. hepp

    hepp Guest

    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?
    hepp, Aug 30, 2004
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Aug 30, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stu
    Replies:
    2
    Views:
    459
  2. bugbear
    Replies:
    1
    Views:
    1,011
    bugbear
    Nov 4, 2005
  3. Andrei

    killing processes on win xp

    Andrei, Feb 11, 2004, in forum: Python
    Replies:
    1
    Views:
    530
    Yen-Ting Chen
    Feb 13, 2004
  4. x1
    Replies:
    15
    Views:
    255
  5. bsder
    Replies:
    10
    Views:
    504
    Big and Blue
    Dec 2, 2005
Loading...

Share This Page