# pid of nohup process

**URL:** <https://community.unix.com/t/pid-of-nohup-process/176702>\
**Category:** Shell Programming and Scripting\
**Created:** [October 17, 2007, 6:02am UTC](https://community.unix.com/t/pid-of-nohup-process/176702 "2007-10-17T06:02:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rein](https://community.unix.com/letter_avatar/rein/32/6_22734026db12803ebb3e059622ac3534.png) [@rein](https://community.unix.com/u/rein)\
**Post date:** [October 17, 2007, 6:02am UTC](https://community.unix.com/t/pid-of-nohup-process/176702/1 "2007-10-17T06:02:37Z")

</div>

I want to print the pid of a nohup process to a file so later I can use the list of pid's in that file to stop the background processes again.

I use ksh on AIXv5.3:

```nohighlight
nohup /start/script.ksh 1>/dev/null 2>&1
print $$ > .pid

nohup /start/script2.ksh 1>/dev/null 2>&1
print $$ >> .pid

```

But in the .pid file I get the pid of the script that contains the nohup statements instead of the pid of the nohup statement, what I would expect.

---

<div class="post-metadata">

**Author:** ![mvijayv](https://community.unix.com/letter_avatar/mvijayv/32/6_22734026db12803ebb3e059622ac3534.png) [@mvijayv](https://community.unix.com/u/mvijayv)\
**Post date:** [October 23, 2007, 6:33pm UTC](https://community.unix.com/t/pid-of-nohup-process/176702/2 "2007-10-23T18:33:25Z")

</div>

$$ gives you the pid of the current shell that is why it is giving you the pid of the script or session that is calling the nohup statement. you need to place the print $$ within script.ksh and script2.ksh or you will have to get the pid list of the child processes of the current shell. I'll try to paste that part once I figure it out ... but for now see if it is feasible to place those commands within script.ksh and script2.ksh.

hope this helps,  
Vj

---

<div class="post-metadata">

**Author:** ![mvijayv](https://community.unix.com/letter_avatar/mvijayv/32/6_22734026db12803ebb3e059622ac3534.png) [@mvijayv](https://community.unix.com/u/mvijayv)\
**Post date:** [October 23, 2007, 6:42pm UTC](https://community.unix.com/t/pid-of-nohup-process/176702/3 "2007-10-23T18:42:03Z")

</div>

got it ....  
$! gives the child pid .....

```nohighlight
nohup /start/script.ksh 1>/dev/null 2>&1
print $! > .pid

nohup /start/script2.ksh 1>/dev/null 2>&1
print $! >> .pid

```

Vj
