I am using this approach to run a process in background.
"$@" &>/dev/null &disown
How do I achieve the following -
- Get the background
- Return it so that it can be consumed in another script?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
The process ID of the most recently started background job is available to the shell as
You may, for example output it to a file or to standard output:
"$@" &>/dev/null & disown printf '%d\n' "$!" >background.pid
Another script may then
./first-script.sh some command line thepid=$( <background.pid )
Alternatively, if the first script just outputs the process ID to standard output, the second script could
thepid=$( ./first-script.sh some command line )