Can a Bourn Shell Script put itself in the background?

Barry Byrne barry.byrne at
Thu Jun 4 14:42:25 UTC 2009

> From: owner-freebsd-questions at 
> [mailto:owner-freebsd-questions at] On Behalf Of 
> Martin McCormick

> I tried 
> bg $$
> but $$ is the current process invoked just as $! is the process
> of a backgrounded process started by that shell.
> 	So, can I make a shell script background itself after
> starting?
> Right now, I remind my coworkers to append the & after the
> script name. the bg command expects a job number, not a process
> ID.


If you mean you'd like to be able to put a script that is already running
into the background, then you could press CTRL-Z to suspend the process.
Then running 'jobs' will list the job id. Then 'bg jobnumber' (probably 1)
should put it into the background.



More information about the freebsd-questions mailing list