Skip to content

Instantly share code, notes, and snippets.

@stfp
Created May 19, 2011 03:21
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stfp/980127 to your computer and use it in GitHub Desktop.
Save stfp/980127 to your computer and use it in GitHub Desktop.
Java class to kill the current process using JNA
/* Requires JNA
* Get jna.jar here: http://java.net/projects/jna/sources/svn/show/trunk/jnalib/dist
*/
import com.sun.jna.Library;
import com.sun.jna.Native;
public class SelfKiller
{
private interface CLibrary extends Library
{
CLibrary INSTANCE = (CLibrary) Native.loadLibrary("c", CLibrary.class);
int getpid ();
void kill(int pid, int signal);
}
public static void killSelf()
{
int pid = CLibrary.INSTANCE.getpid();
CLibrary.INSTANCE.kill(pid, 9);
}
public static void main(String[] args)
{
SelfKiller.killSelf();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment