Thread: kill a process

  1. #1
    Unregistered
    Guest

    Question kill a process

    Is there a command to get a childs process PID and kill it?

    I am using :

    pid = getpid(); this one kills the main program.

    or
    pid = getppid(); this one kills all of the windows.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Which platform???

    For Win32 ypou could use TerminateProcess()

  3. #3
    Unregistered
    Guest
    Unix platform

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    use the kill() function then - section 2 of the manual

  5. #5
    Unregistered
    Guest
    this is in the main program

    system("./man&");

    which executes another child program.

    how do I kill that program from the main program?

    I am using this but it kills all the windows or the main program. I just want to kill the child process.

    int pid;
    pid = getppid();
    kill(pid,1);

    Thanks again,

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Then use fork() and execl() for creating the process, and you'll have the process ID directly to hand

    Something like this
    Code:
    int pid;
    pid = fork();
    if ( pid == 0 ) {
        execl( "/bin/man", "/bin/man", NULL );
    }
    
    /* here, man will be running with process ID pid */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. init adopts zombie process?
    By password636 in forum Linux Programming
    Replies: 4
    Last Post: 07-01-2009, 10:05 AM
  2. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  3. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  4. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM