0

In bash, I know that if I run:

my_executable arg1 arg2 &

I've started a background job; and I'll also get its id and pid printed on the console, e.g.:

[1] 25103

but how do I place those numbers in variables? This doesn't work:

my_executable arg1 arg2 & |  read jid_in_brackets pid

... it's a syntax error.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • You can get the PID with `$!`. Getting the job number is more difficult. See [How to programmatically get the job id of a newly backgrounded process in Bash](https://unix.stackexchange.com/q/712525/264812) and [How to get the Job ID?](https://unix.stackexchange.com/q/110911/264812). [In shell, when I run process in background, how can I get the "\[job number\] \[PID\]"](https://unix.stackexchange.com/q/570428/264812) may also be of interest. – pjh Apr 04 '23 at 13:02

0 Answers0