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.
- 07-28-2005 #1Just 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?
- 07-28-2005 #2Linux Guru
- Join Date
- Nov 2004
- Posts
- 6,110
You should be able to get the PID by running
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.Code:/sbin/pidof mencoder
- 07-28-2005 #3Just 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 ?
- 07-28-2005 #4Linux 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
- 07-30-2005 #5Linux 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.


Reply With Quote
