Find the answer to your Linux question:
Results 1 to 7 of 7
I have a question regarding how to keep track of the process which started from one process, and able to communicate to it, then kill it if necessary. Currently, the ...
  1. #1
    Just Joined!
    Join Date
    Aug 2005
    Posts
    19

    linux c/c++ code to start/kill the process

    I have a question regarding how to keep track of the process which started from one process, and able to communicate to it, then kill it if necessary.
    Currently, the easiest way is use the system() call to start the process, but no PID can be track, impossible to kill it.
    Any good idea of how to handle the process.

  2. #2
    Linux Guru techieMoe's Avatar
    Join Date
    Aug 2004
    Location
    Texas
    Posts
    9,496
    why not use fork()? That will return a PID you can use to monitor the child process.

    http://www.cs.bsu.edu/homepages/fwo/cgi-bin/man.pl?fork
    Registered Linux user #270181
    TechieMoe's Tech Rants

  3. #3
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575

    Re: linux c/c++ code to start/kill the process

    Quote Originally Posted by dragondad
    I have a question regarding how to keep track of the process which started from one process, and able to communicate to it, then kill it if necessary.
    What kind of communication do you want to do ?

    By the way apart from fork check out also execve

  4. #4
    Just Joined!
    Join Date
    Aug 2005
    Posts
    19

    high level abstraction layer of process management

    Actually, I need to do some kind of process management from the main process, when main process parse the config file, it will determine how to start each sub process (to handle different task), each process should able to be started and killed individually, and need the communication channel (such as pipe or message queue) between the main process and the subprocess.
    Any suggestion of the framework or process management package can be used. Thanks.

  5. #5
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    For pipes check out man 3 mkfifo
    For killing them man 2 kill

  6. #6
    Just Joined!
    Join Date
    Jul 2005
    Posts
    28
    Have a look into linux threads. I think it's not wise to start different processes for a single program, and ofcourse you can share normal datas such as C variables.

  7. #7
    Just Joined!
    Join Date
    Sep 2007
    Posts
    1

    Kemo

    You can use getpid(), it will return current process id.
    Use getppid(), it will return parent process id.
    For process and threads communications you can use shared memory. It is much easier, much faster. Search for it, if you didn't find anything useful ask again and i'll post useful things for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...