How to get the process id after running an application from Java under Linux

Use the following sample code to get the pid(process id) on *nix variants, after running it as a command from Java using Runtime.exec() .

The command variable, in my case, was running another Java application.

try {

Process  process=Runtime.getRuntime().exec(new String [] {"sh","-c",command+"  &  echo $!"} );
BufferedReader br=new BufferedReader(new InputStreamReader(process.getInputStream()));

String ps=br.readLine();
int pid=Integer.valueOf(ps);
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}

*Solution* – When I right click a file in Windows explorer.exe crashes

Right Click MenuI just had this annoying problem which seems to only happen when I right click *some, but not all* files. If you also have this problem, you have come to the right place because I actually found a way to solve it! 🙂

Right Click Menu

The problem is that one of your shell extensions has some problems loading when you right click on those particular files. Just install ShellExView and you will be able to see all your shell extensions. All you have to do is just disable the shell extensions of those applications that you have recently installed. Do it one by one, and you will find which extension is causing up the damn trouble! In my case it was the latest version of TortoiseSVN, but people around seem to be also having problems with other software too.

Normally, I would recommend using Fast Explorer 2008, as it also has the ability to show all extensions residing on your system and *more*; but what it doesn’t have is the ability to sort the shell extensions by their “File Created Time”. IMO, this is a great feature to have in an application like this. So I am hailing the developers from here to also include it 🙂

As always, there may happen to be another cause for these explorer crashes, although these are the most popular one as far as I have seen.

Oh and by the way, here is a more detailed walkthrough if you need any more help.