[ALUG] sudo &

Brett Parker iDunno at sommitrealweird.co.uk
Thu Jun 8 12:40:24 BST 2017


On 08 Jun 11:32, Mark Rogers wrote:
> Is there an easy was to launch a process with sudo and send it into
> the background?
> 
> $ sudo myapp &
> .. will go straight into the background then stop, waiting for a
> password to be entered. So I have to bring it back to the foreground
> (fg), enter the password, stop it (ctrl-z) then send it back into the
> background (bg).
> 
> Of-course what normally happens is that I don't realise it's stopped
> at all, only to come back several hours after a long process should
> have been running to find it hasn't yet started....
> 
> I'm sure there's a better way?

So, how about looking at the magical man page... or even sudo --help...

then you'll find that there's this magic option:

(man page)
     -b, --background
                      Run the given command in the background.  Note
                      that it is not possible to use shell job control
                      to manipulate background processes started
                      by sudo.  Most interactive
                      commands will fail to work
                      properly in background mode.

(--help)

  -b, --background            run command in the background
  
So, that means that sudo will stay in the foreground and ask for your
password, as you'd expect, but then fork the process off in to the
background.

Simples.

Thanks,
-- 
Brett Parker



More information about the main mailing list