How can I kill a background process that was executed by calling a system function in C. For example, I have a compiled request for the application "fooprocess". Then I want to write a program that will execute the fooprocess application in the background using the system function, please see the code below,
const char app[] = "fooprocess &"; system(app);
As you can see, there is a &. so that I can run the fooprocess application in the background. How can I kill this fooprocess?
Many thanks.
, PID. , system, , fork + exec.
system
system("foo &"); , /. gigantic: pid, , pid , , , pid .
system("foo &");
( , , ), , - system fork exec posix_spawn. ( , init), wait/waitpid, wait pid , ..
fork
exec
posix_spawn
init
wait
waitpid
, :
ps -axc|grep -i myApp|awk '{print $1}' | tr -d '\n' | xargs -0 kill
system() :
system("ps -axc|grep -i myApp|awk '{print $1}' | tr -d '\n' | xargs -0 kill");
.