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)
{
}
}