Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I detach command:

$ command &

The result is a printout to STDOUT:

[1] < PID >

I would like to monitor this PID. However, I cannot write this output anywhere but STDOUT! How can I redirect this to a file or a variable?

I have tried:

$ command 1> ./temp.txt &

But this still finds its way to STDOUT!

Thanks in advance for the help!

share|improve this question
up vote 10 down vote accepted

$! should contain the PID of the last background process. Something like...

$ command &
$ echo $! > temp.txt

Should give you a file named temp.txt with the PID in it.

Or on one line...

$ command & echo $! > temp.txt
share|improve this answer
Awesome. This does not answer my exact question, but this is even better! – Daeden Jul 17 '13 at 6:44
Yeah, I think the problem is stdout is the output of the command you're running, but the id is coming from the shell. So to capture it with stdout you'd have to actually execute it in a subshell some how and capture the stdout of that. Just thinking out loud about what's going on, haven't tested that. – Bill Heller Jul 17 '13 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .