I recently got a server and am quite new to servers in general, I'm trying to keep the server running in the background while I do other stuff on the server, any commands I try just execute as minecraft commands and ctrl+a,d doesn't work. I am running Ubuntuserver 22.04.3
1 Answers
I am not quiet sure you actually mean detach, but rather, most likely, send the running process/command to background and keep it running there while freeing up the prompt for your other commands, that can be achieved by first, pressing Ctrl+z to stop(keep this in mind) the process while sending it to the background freeing up the prompt as a result like so (taking e.g. sleep 1h as an example long running job):
$ sleep 1h
^Z
[1]+ Stopped sleep 1h
$
... Now that the prompt is freed up, you can then, resume the job in the background with bg like so:
$ bg
[1]+ sleep 1h &
$
... and there you have it, your job is running in the background and you can verify that with jobs like so:
$ jobs
[1]+ Running sleep 1h &
$
... to bring it back to foreground again, use fg like so:
$ fg
sleep 1h
... and of course you can repeat the above steps sending it back and forth as needed.
On the other hand to detach a job from the current terminal sending it to the background to run in its own shell, run it at the first place with & disown like so:
$ sleep 1h & disown
[1] 6428
... but it will no longer belong to the current running shell in the current running terminal and jobs will not return it:
$ jobs
$
... and it will keep running even if you close the terminal ... but, interacting with it is not as simple anymore.
- 34,963