Process id of the exe started with nohup


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Process id of the exe started with nohup
# 1  
Old 04-28-2009
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();
# 2  
Old 04-28-2009
I think you are getting a process id of the external echo command you are invoking inside back ticks.

Check this :-

Code:
#!/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
# 3  
Old 04-29-2009
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I need to save a pid of a child started with $: su <user> -c “nohup …”

Hello, I want to save pid of a child process but I get empty file. su myuser -c "nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid" This one works: nohup ./mydaemon.sh >/dev/null 2>&1 & print $! > mydaemon.pid Please help. Thank you in advance. (2 Replies)
Discussion started by: vincegata
2 Replies

2. Shell Programming and Scripting

how to check whether a process started at particular time

I want to check whether a particular process has started at 10:00a.m or not. I can check process by ps -fu but dont know how to check it with respect to time. Could anyone help me with this? ---------- Post updated at 11:14 AM ---------- Previous update was at 10:52 AM ---------- can i use... (9 Replies)
Discussion started by: kishore kumar
9 Replies

3. Programming

how can I get to know what threads run within process java.exe on windows

I am writing java application on windows. There are more than 100 threads run within java.exe. I want to know what threads run within process java.exe so that I can find out if there are abnormal java threads. (4 Replies)
Discussion started by: mika
4 Replies

4. UNIX for Advanced & Expert Users

nohup and background process

What is the difference between running a process using nohup and running a process in background ? Please explain (6 Replies)
Discussion started by: srksn
6 Replies

5. UNIX for Advanced & Expert Users

how to know that a perticular process is started!!!

Hi all, I wanted a write a script which will start executing whenever a particular process will starts running in a background. Is there is any way in Unix if a directory contents changed then a signal/Interrupt will generated and by taking status of that interrupt I can execute some scripts.... (11 Replies)
Discussion started by: zing_foru
11 Replies

6. UNIX for Dummies Questions & Answers

Process started on console

Please can someone describe what causes undesired process startup on system console. ps -ef output is like: root 1763 1 0 16:22:24 console 0:00 /bin/sh /usr/System........ process is blocking system console for any access (2 Replies)
Discussion started by: zverzak
2 Replies

7. Programming

Child process is not getting started

Hi, When i m trying to run below code,its entering into wait stage. output: In parent pid=2134 // some random value assigned to child process parent waiting..... and then it keeps on waiting for child to get terminate Y this child is not getting... (5 Replies)
Discussion started by: Crab
5 Replies

8. UNIX for Advanced & Expert Users

kill scripts which are started using nohup

i have scipt which is calling some other scripts and some built-in utilities like SED, find etc.. i started this script using nohup (e.g: nohup scriptname &) now i want to kill this script and all the child processes of this script. the problem is, process id of child processes are... (4 Replies)
Discussion started by: gfhgfnhhn
4 Replies

9. UNIX for Dummies Questions & Answers

is there any way to know how much time process was running from the moment it started

i have process that was started few days ago , is there way to know by its id how long it was alive in the system ? Thanks (2 Replies)
Discussion started by: umen
2 Replies

10. Shell Programming and Scripting

PID of process started in background??

I am having a problem getting the PID of a process I start in the background is a csh. In tcsh and sh it's simple $! give it to you But in csh this just returns Variable syntax From the man page it should work but it doesn't???? Any help. (2 Replies)
Discussion started by: stilllooking
2 Replies
Login or Register to Ask a Question