Process id of the exe started with nohup

Hi,

I have a strange problem.
In my shell script, i am startting another program (a c++ exe) with nohup .
I am getting the process id of this started process with using $!
I am writing this process id into another file so that i can keep checking for this process ids to check whether the process is completed.
Additionally, the c++ exe also writes its process id into the log file.

When i check the process ids that i am capturing from the shell script and the process id from the log file of the exe, both are not matching.
Process id from the shell script is the parent process id not the child's process id.

Could someone please tell me what is wrong wiht my approach and how to get the process id of the child process accuraetly in my script.

below is the piece of shell script that i m using:

### Shell Script ########

nohup BDE arg1 arg2 arg3 &
proc_id=`echo $!`
echo $proc_id >> proc_id_file

###### code in c++ to get process id ####

process_id = getpid();

I think you are getting a process id of the external echo command you are invoking inside back ticks.

Check this :-

#!/bin/ksh

echo "Current script pid = [$$]"
nohup sleep 60 &
echo "Process id of sleep [$!]"

i.e So try just procid=$! for the last child spawned

Hi lavascript,
thanks for your inputs.

what i observed is this behaviour is not consistent.
Initially i used to execute my C++ exe file without nohup. I used to run it as a background process..
Now i changd it to nohup... then i observed this problem.
But today when i executed it again, there is no problem.. with my existing logic itself, i got the correct pids..
Not sure what is the problem.

Anyway, to be on safer side, i will go with ur suggestion.

Thanks again