Writing my own pid

2003-08-31 08:55:13 PM
Is it possible to write a pid (process id) when I launch a Java
program from command line in Unix (Solaris)?
Command line will be the normal "java MyProgram param1 ...". When
doing this from shell (sh) init script I can use the variable $! as
last started backgroup process id, but I'm having some problems when
doing this with root user and "su"ing to some other user.
I've tried something like this:
cd $HOME
/usr/bin/nohup /usr/java/bin/java MyProgram>>mylog.log &
echo $!>MyProgram.pid
su - dummy -c "( cd $HOME ; /usr/bin/nohup /usr/java/bin/java
MyProgram>>mylog.log & )"
echo $!>MyProgram.pid
While runing this case 2 as a root, I su to another user dummy and
launch the program. After that I dont have $! variable...