Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ubuntu Java: Find a specific program's pid and kill the program

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

like image 903
Abraham Miguel Espiritu Avatar asked Oct 14 '11 01:10

Abraham Miguel Espiritu


People also ask

How do I kill a process with a specific name in Linux?

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.

How do I find and kill a Java process in Linux?

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.

How do you kill a Java program?

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.

How do you kill a program in shell script?

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.


1 Answers

You might try ps -aux | grep foobar for getting the pid, then issuing the kill command against it, alternatively you might want to use pkillfoobar, in both cases foobar being the name of the app you want to terminate.

like image 112
Nano Taboada Avatar answered Oct 08 '22 22:10

Nano Taboada