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();
}

Output last inserted row id in TSQL in a stored procedure

It is quite easy to get the last inserted row id in TSQL.

Just create a stored procedure as below.

CREATE PROCEDURE InsertRow
( @parameter1 int, @parameter2 varchar(255), @NewId int OUTPUT )
AS

Read the rest of this entry »