How can I kill a background process that was executed using a system function call in C language. Like for example I have a compiled application call "fooprocess". Then I want to write a program that will execute the fooprocess application in the background using the system function, please kindly see below the code,
const char app[] = "fooprocess &";
system(app);
As you can see there is a "&" character so that I can run the fooprocess application in the background. How can I kill this fooprocess?
Many thanks.
pkill. pkill is one of the commands that can directly kill a background process, using the process name.
The killall command is used to kill processes by name. By default, it will send a SIGTERM signal. The killall command can kill multiple processes with a single command.
To interact with the process you need its PID. I'm not sure if it's possible with system
but one alternative is to fork the process yourself using fork + exec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With