The program Boblight does not run in background. There is no noticeable difference between executing
and
How can I solve this problem that the console will not block further inputs?
This question came from our site for professional and enthusiast programmers.
The [1] 2289
after your background command shows it worked, and was indeed put into the background.
But the output of your command will still go to the terminal, unless you redirect. Here is the comprehensive way to do that:
If you want both stdout and stderr to go to the same file:
And, of course, if you don't care about the output of either or both streams, you can send to /dev/null
instead of a filename.
(that example throws away standard output, but keeps stderr, just in case something goes wrong.)
UPDATE
The above is based on no knowledge of what boblightd is. I see in another answer it has a daemon mode, so that should be used instead in this case.
BTW, the above assumes sudo
will not prompt for a password, and that you will not close the terminal window. For the former, I personally normally use sudo bash
then, would type boblightd >std.txt 2>err.txt &
. Another way is to do sudo ls
or some harmless command to make sure the access gets cached.
For the latter, nohup
is the magic command to make sure it stays running even after you Leave The Building. It would go after the sudo
and before the actual command. E.g. sudo nohup boblightd >std.txt 2>err.txt &
. Or sudo bash
then nohup boblightd >std.txt 2>err.txt &
, then exit
(to leave the root shell).
I think you can use nohup command like this:
this will put the output of your command to nohup.out file in current directory.
Also you can use screen command like this :first create a screen :
then run your command:
To save the screen and return to the terminal, type Ctrl+AD (Ctrl+A is the hint for screen
that you want to do something and D then 'd'etaches from the session without stopping it).
restore your screen :
You'll have to redirect stdout and stderr to something else than their defaults to hide them. @devnull's comment shows how to do this. That's a first step.
If you simply use &
to detach your program, it will be killed automaticaly when you logout. That's probably not what you want. You'll have to use the nohup
command to prevent this:
nohup sudo boblightd > boblight.out 2> boblight.err < /dev/null &
Note that sudo
will probably ask for a password: it won't get any, and you won't notice it's asking you for one, as every output/input is redirected. You have different solutions to achieve this anyway:
sudo
command before, sudo
will save your password. That's the quick'n'dirty way.&
, give sudo
the password, then send the process to background with CTRL + Z.Boblightd
In the case of boblightd the output sent to stderr is already captured in it's log file (defaults to ~/.boblight/boblightd.log), so this doesn't need to be captured and can be discarded. Also, boblight doesn't fork by default but can be made to do by include the -f in the command.
I suggest you try the following:
(details from the project documentation)
More generally
Processes started from the shell will terminate when the shell exits. As others have pointed out using Ctrl-Z while running a process in the foreground returns control to the shell. However, the process is placed in a stopped state at this point. The bg
command will be needed to get the process running again but stay in background. It requires either a process id or the job number (as usual job numbers are prefixed with a %), so using your second example you would issue either
or
The process will now be running in the background but is still attached to the shell. The link to the shell can be severed using the disown
command, which saves the confusion with nohup/sudo. As with bg
, disown
requires only the process id or job number
e.g.
You can now exit the shell safely as if you had run the process with the nohup
command
Since the answer is pretty much laid out in comment already. I felt like it would be good to post a little bit of explanation on it as an actual answer.
So the way to go is: sudo boblightd > /dev/null 2>&1 &
There are 3 important parts here. Most important is &
at the end of line. It makes the shell not wait for command to end before giving back control. It also takes out the standard input from keyboard. It puts the job into background.
But this still would leave the output back into console. To prevent this there is >
symbol which redirects the standard output (to /dev/null
in this case).
At this point you can still get output from called command get to screen. This would be the standard error. So lastly there is 2>&1
magic. This redirects output from the standard error stream to the standard output.
2
and 1
come from standard file descriptors. 0
would be stdin
, 1
- stdout, 2
- stderr.
You could redirect output to a file if you need it.
There are command designed to interact with jobs in back ground. jobs
and fg
.
You'll get a new group of playable LEGO DC Comics characters, vehicles, achievements, as well as a new story experience in the LEGO Batman 3: Beyond Gotham universe. Lego batman 3 beyond gotham the squad dlc-bat. Who all is in this Squad? In The Squad add-on content pack, a mysterious figure has infiltrated Belle Reve Penitentiary, and it’s up to players to smash their way through the prison as Deadshot, Deathstroke, Harley Quinn, Captain Boomerang and other members of The Squad to hunt down this infiltrator before Amanda Waller's—and The Squad's—secrets are uncovered. The Squad DLC pack will be available in early 2015 for the PS4, Xbox One, Xbox 360, PS3, and PC. What's their mission?
You could also play with more advanced solutions such as screen
command if needed.