Whenever I type killall java -9 ,all java process is killed, even if i change the process name. So Is there an way to protect the java process being killed by 'killall java -9'

  • 2
    Making a program that cannot be terminated from command prompt seems kind of...dangerous
    – Jeffrey
    Aug 29, 2012 at 1:33
  • 1
    -9 is SIGTERM, which I believe there is no way to ignore that. And, it is the PROCESS being killed instead of THREAD Aug 29, 2012 at 1:34
  • @Jeffrey that's what I'm thinking too :/
    – PicklishDoorknob
    Aug 29, 2012 at 1:34
  • 1
    You could run another (non-Java) process to restart your Java process when it unexpectedly closes.
    – EthanB
    Aug 29, 2012 at 1:45
  • I think that the best answer is "just don't do it". (Like you wouldn't run "rm -rf" in the root directory!)
    – Stephen C
    Aug 29, 2012 at 1:49

1 Answer 1


The simple solution is to run the process with a different user. Then, you (as your current user) would not have permission to kill all processes called java, unless you were root.

I, deltik, do not have a java process running. top shows:

Processes: 80 total, 3 running, 1 stuck, 76 sleeping, 435 threads      21:22:54
Load Avg: 1.66, 1.47, 1.40  CPU usage: 33.49% user, 2.65% sys, 63.85% idle
SharedLibs: 7552K resident, 4480K data, 0B linkedit.
MemRegions: 15059 total, 1858M resident, 32M private, 372M shared.
PhysMem: 298M wired, 2332M active, 1289M inactive, 3918M used, 176M free.
VM: 164G vsize, 1041M framework vsize, 490174(73) pageins, 7225(0) pageouts.
Networks: packets: 1543452/932M in, 1286039/414M out.
Disks: 103231/3309M read, 218839/2343M written.

1159  java         108   02:28:38 45/2 1    somebody
1769  top          4.0   00:10.32 1/1  0    root
765   bash         0.0   00:00.00 1    0    deltik

So this is my output when I try killall -9 java:

Deltik-iMac:~ deltik$ killall -9 java
No matching processes belonging to you were found

I cannot kill a java process owned by somebody.

  • 1
    Nice,+1. @jilen you could also use kill instead of killall to kill only the specific processes that need to go.
    – terdon
    Aug 29, 2012 at 2:42
  • @terdon there is another script that use killall, I think I should better not change it
    – jilen
    Aug 29, 2012 at 4:08
  • By run java as another user , I cannot access the home folder of the user.
    – jilen
    Aug 29, 2012 at 4:09
  • You would presumably know the password of that user, so you could su somebody.
    – Deltik
    Aug 29, 2012 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.