Find the answer to your Linux question:
Results 1 to 5 of 5
my program exectute mencoder program(from MPlayer) by using system function in program. I want to kill process of mencoder in my program. ex) int main() { // running program } ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2005
    Location
    South Korea
    Posts
    19

    I want to kill process


    my program exectute mencoder program(from MPlayer) by using system function in program.

    I want to kill process of mencoder in my program.

    ex) int main()
    {
    // running program
    }

    void run_mencoder()
    {
    // system("mencoder");
    }

    void kill_mencoder()
    {
    // system("kill -9 ????"); //????->mencoder process ID
    }

    how to know process ID of mencoder?

  2. #2
    Linux Guru bigtomrodney's Avatar
    Join Date
    Nov 2004
    Location
    Ireland
    Posts
    6,133
    You should be able to get the PID by running
    Code:
    /sbin/pidof mencoder
    The only negative aspect will be if it returns more than one value, you may have to recode for that. It is nice because it returns a very small amount of data, just the PID I think.

  3. #3
    Just Joined!
    Join Date
    Jul 2005
    Location
    South Korea
    Posts
    19

    How to get return value of "pidof" in my application ?

    Thank you very much for your reply

    I want to use "pidof" program in my app by calling system function.

    system function can't return value of "pidof"

    How to get return value of "pidof" in my application ?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Chicago (USA)
    Posts
    1,028
    kill `pidof menencoder`

    In Bash, for anything inside ``, standard out is the script, not the screen.

    Or you can use this little script I made for myself:
    Code:
    pid=`pidof $1`
    if [ "$?" != "0" ]; then
       exit
    fi
    kill $pid

  6. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    If you're writing a C program, don't use system, use fork() and exec(). That way, you can save the PID of your child process and kill it with a kill(2) system call.

Posting Permissions

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