Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have created a Java application that can start processes and capture their PIDs so that the application can monitor the process. The user may later choose to kill the whole process tree (session). I have done this by utilizing setsid. One scenario is starting a whole bunch of different processes via a shell script by: setsid <shell script>. The PID represents the new session and killing it will kill all processes spawned in that session. It worked great until Ubuntu 12.10 was released. Now i cannot kill all sessions started via setsid. One example is Firefox and Google Earth. Gedit can still be killed if started through setsid.

I created a simple test program that perform kill -SIGTERM -PID. The test program manages to kill firefox started via setsid under Ubuntu 12.04 but not under Ubuntu 12.10. I don't know what has changed. I have executed the program in both distributions using OpenJDK 6, 7 and Oracle JDK 6.


public class kill
{
        public static void main(String[] args)
        {
    try 
        {
        System.out.println("kill -SIGTERM -" + args[0]);
        Process proc = Runtime.getRuntime().exec("kill -SIGTERM -" + args[0]);
        int exitVal = proc.waitFor();
        System.out.println("Exit value: " + exitVal); // often 1 under Ubuntu 12.10
        }
    catch (Exception e)
        {
        }
}

share|improve this question
    
After som testing I've found that on Ubuntu 12.10 it's possible to kill the process group if a signal isn't specified, e.g: kill -- -<PID> –  Steve Nov 28 '12 at 9:51
    
To clarify, kill -SIGTERM -<PID> works in the bash shell in Ubuntu 12.10 but not if executed through Runtime.getRuntime.exec(), one qould have to remove the 'SIG' part as described above :-) –  Steve Nov 29 '12 at 7:17
    
You should post this as an answer. –  Eric Carvalho Nov 29 '12 at 12:07

1 Answer 1

In Ubunutu 12.04 and Centos 5 + 6 it's possible to use the signal name like SIGTERM but on 12.10 one has to use -TERM instead. Changing my code so that the signal names don't have the prefix 'SIG' seem to work well on 12.04 and 12.10. So the example code that works for me is:

Process proc = Runtime.getRuntime().exec("kill -TERM -" + args[0]);

To clarify, kill -SIGTERM -<PID> works in the Bash shell in Ubuntu 12.10 but not if it's executed through Runtime.getRuntime.exec(), one qould have to remove the 'SIG' part as described above.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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