Thanks for the reply. But, it just went above my head...sorry
Are there any pointers to this or could you make it a little more simpler
What is the parent process in my case ? PID corresponding to SSH
Just by luck, I found the solution. I gave a & in the command at I get the PID of the submitted job on my local machine.
ssh -f remote-host "sh my-process.sh &"
and it gave me
[1] 10327
10327 is the process id on the remote machine.
What does [1] signify ?
'job' 1. If you use the jobs command, you'll see it's been assigned an id of 1. You can then pass this to the fg and bg commands if you want.
FYI the environment variable $! get populated with the PID of the last command set to run in the background by the current shell or script. Much like $? is the exist code from the last command.
There is a difference in the behaviour of KornShell and Bash you might want to observe: bashs child processes put in background won't be terminated once the process controlling that terminal dies. KornShell processes will, however, die with their parents until they are started with the "nohup" (no hangup [upon loss of terminal]) command.
To explain that in more common terms: when you issue 'ssh -f host "cmd"' you basically open an interactive session like you would log on, issue "cmd" in this session and then close it again. The whole procedure will normally wait until "cmd" is finished. By logging on, you create a (pseudo-)terminal, which will be closed when you log off.
Now consider a background process as "cmd". It is not possible to wait until it finished, because that could possibly be forever. In fact you just want to *start* it, not waiting for its end. So you start a (in fact interactive) shell, start in this shell a process in background and then want to terminate the shell - the child will, if this shell is a KornShell - die with the parent.
What you could do in this case is:
start the job in background
find out its PID (inside the process environment)
issue a "nohup -p PID"
terminate the controlling shell - the nohup-ped process will survive
"cmd" in this case would look like (i will use vmstat as an example):
The output of "jobs" will decorate the last recently issued background job with a "+", which means, this is the job which will become the foreground job when the command "fg" is issued. The sed-statement just extracts the PID from this line.