child pid in ZSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting child pid in ZSH
# 1  
Old 08-30-2007
child pid in ZSH

I am using ZSH shell in Linux.

I am calling a child program in background mode parallely (say 2-3 threads). I have problem in handling the temporary files of these child programs since the temp file names are unique for all the child process.

To distinguish i want to use the pid in the temp files. But when I use the $$ to fetch the pid it is same across all the chils process since the obtained pid is of the master program which called all these.

Could anyone help me to identify the PID of the current child process so taht i cann append in the temp file names. From the previos threads i saw there is a function called getpid() to get the pid. But am not sure of the usage..
# 2  
Old 08-30-2007
When you spawn a child process (not a thread), the pid of the process should be in $!

eg

Code:
$ echo &
[1] 21616

[1]+  Done                    echo
$ echo $!
21616

# 3  
Old 08-30-2007
Porter,

Thanks for your response.

I think i am not clear in my question.

Actually i am calling another shell script say xyz.sh in the master program abc.sh in a loop for n number of times in the background mode.

The $$ value gives the PID of the master script in the sub program and hence i am not able to use the pid of the script for naming temp files which gets clashed with the temp files of the other parallely running same sub programs running in background.


Actually in ZSH if i use $! i get 0 as result.
# 4  
Old 08-30-2007
Quote:
Originally Posted by dhams
Actually in ZSH if i use $! i get 0 as result.
zsh behaves the same way, spawn a child using & and $! is set to the pid of the child.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 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

Getting child process id for a given PID

HI Am trying to get child process id for a PID using ksh.. ps -ef | grep xntpd root 3342472 2228308 0 12:17:40 - 0:00 /usr/sbin/xntpd root 4522024 6488316 0 12:18:56 pts/0 0:00 grep xntpd root 6291614 3342472 0 12:17:40 - 0:00 /usr/sbin/xntpd Here now i... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

3. Red Hat

Listing all child pid and deleting it in reverse order

Hi , My problem is that I am not able to list all process id of any process. If you see pstree command it shows many process id under https. But if I run ps command its not listing all the process id for httpd. It is just listing the PPID and immediate child process id only. I... (4 Replies)
Discussion started by: pratapsingh
4 Replies

4. Shell Programming and Scripting

how to capture PID for a child script

Hi, I'm looking for a method where we can capture the PID and if possible the progress of child process especially the ones running in background. can anyone help? (6 Replies)
Discussion started by: aman jain
6 Replies

5. Shell Programming and Scripting

In ksh, how does an in-line child sub-process get its own PID?

This is not the same as a few of the other posted items dealing with sub-process pids (that I saw anyway). If zot contains: echo "main mypid: $$ - lastpid: $!" ( echo "block mypid: $$ - lastpid: $! - ppid: $PPID" ps -ef > xxx sleep 5 echo "block mypid: $$ - lastpid: $! - ppid:... (6 Replies)
Discussion started by: MichLab
6 Replies

6. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

7. Programming

Child Process PID

Hi, Can anybody solve this query? A parent process forks 2 child processes. How does the child process know it's PID without the parent process sending it. Apart from the "ps-ef" option, what other options are there if any? (2 Replies)
Discussion started by: skannan
2 Replies

8. UNIX for Dummies Questions & Answers

Script to kill all child process for a given PID

Is there any build in command in unix to kill all the child process for a given process ID ? If any one has script or command, please let me know. Thanks Sanjay (4 Replies)
Discussion started by: sanjay92
4 Replies
Login or Register to Ask a Question