I'm trying to make an application that checks if this specific application is running, then kill the app after a specified amount of time. I'm planning to get the pid of the app. How can I get the pid of the app?
Thanks
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.
Kill a process by the pkill command It allows us to kill a process by entering the matching name of the process. For example, we want to kill all the processes with matching name java, execute the command as follows: pkill java.
You can end a Java program by using the “exit()” method of the Java “System” class. It terminates the currently running JVM. Here, the System. exit() method has a parameter 0, which indicates that the program will terminate without any error.
Ctrl+C sends the SIGINT signal to gedit . This is a stop signal whose default action is to terminate the process. It instructs the shell to stop gedit and return to the main loop, and you'll get the prompt back.
You might try ps -aux | grep foobar
for getting the pid, then issuing the kill
command against it, alternatively you might want to use pkill
foobar
, in both cases foobar
being the name of the app you want to terminate.
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