How can I run a command which will survive terminal close?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
redshift
I can't close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?
command-line terminal process background-process
add a comment |
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
redshift
I can't close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?
command-line terminal process background-process
4
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
To anyone facing the same problem: Remember, that even if you typeyourExecutable &
and the outputs keep coming on the screen andCtrl+C
does not seem to stop anything, just blindly typedisown;
and pressEnter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.
– Nav
Apr 21 '16 at 11:18
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17
add a comment |
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
redshift
I can't close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?
command-line terminal process background-process
Sometimes I want to start a process and forget about it. If I start it from the command line, like this:
redshift
I can't close the terminal, or it will kill the process. Can I run a command in such a way that I can close the terminal without killing the process?
command-line terminal process background-process
command-line terminal process background-process
edited Mar 7 at 12:31
sondra.kinsey
1168
1168
asked Nov 12 '10 at 22:57
MatthewMatthew
1,79741411
1,79741411
4
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
To anyone facing the same problem: Remember, that even if you typeyourExecutable &
and the outputs keep coming on the screen andCtrl+C
does not seem to stop anything, just blindly typedisown;
and pressEnter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.
– Nav
Apr 21 '16 at 11:18
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17
add a comment |
4
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
To anyone facing the same problem: Remember, that even if you typeyourExecutable &
and the outputs keep coming on the screen andCtrl+C
does not seem to stop anything, just blindly typedisown;
and pressEnter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.
– Nav
Apr 21 '16 at 11:18
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17
4
4
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
To anyone facing the same problem: Remember, that even if you type
yourExecutable &
and the outputs keep coming on the screen and Ctrl+C
does not seem to stop anything, just blindly type disown;
and press Enter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.– Nav
Apr 21 '16 at 11:18
To anyone facing the same problem: Remember, that even if you type
yourExecutable &
and the outputs keep coming on the screen and Ctrl+C
does not seem to stop anything, just blindly type disown;
and press Enter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.– Nav
Apr 21 '16 at 11:18
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17
add a comment |
11 Answers
11
active
oldest
votes
One of the following 2 should work:
$ nohup redshift &
or
$ redshift &
$ disown
See the following for a bit more information on how this works:
man nohup
help disown
Difference between nohup, disown and & (be sure to read the comments too)
4
The second one (redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?
– Matthew
Nov 13 '10 at 0:52
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly wantnohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with;
(redshift &; disown
)
– Michael Mrozek♦
Nov 13 '10 at 3:14
9
@Michael: Both;
and&
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use&;
in preference to just&
(it works, but it is a bit redundant).
– Chris Johnsen
Nov 13 '10 at 4:29
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
Also,redshift &!
will disown redshift immediately.
– user26112
Apr 21 '13 at 18:30
|
show 4 more comments
If your program is already running you can pause it with Ctrl-Z
, pull it into the background with bg
and then disown
it, like this:
$ sleep 1000
^Z
[1]+ Stopped sleep 1000
$ bg
$ disown
$ exit
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwidisown
does not disconnect stdout or stderr. Howevernohup
does, as does>/dev/null
(disconnect standard out),2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.
– ctrl-alt-delor
Jul 21 '16 at 22:08
|
show 3 more comments
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree
, for example when running kate &
in Konsole:
init-+
├─konsole─┬─bash─┬─kate───2*[kate]
│ │ └─pstree
│ └─2*[konsole]
To make the kate
process detached from konsole
when you terminate konsole
, use nohup
with the command, like this:
nohup kate &
After closing konsole
, pstree
will look like this:
init-+
|-kate---2*[kate]
and kate
will survive. :)
An alternative is using screen
/tmux
/byobu
, which will keep the shell running, independent of the terminal.
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
add a comment |
You can run the process like this in the terminal
setsid process
This will run the program in a new session.
As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1) It doesn't print an annoying message aboutnohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output ofjobs
.
– Mikel
Nov 6 '12 at 22:24
add a comment |
Though all of the suggestions work well, I've found my alternative is to use screen
, a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name
. Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl+A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl+A and 0 or the newer session by hitting Ctrl+A and 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name
. This will reconnect you to that remote session.
add a comment |
The shell-only way to do all this is to close stdin and background the command:
command <&- &
Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.
Disadvantage is that you can't do this after the fact.
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
add a comment |
I have a script to:
Run arbitrary commands in the background
Stop them from being killed with the terminal window
Suppress their output
Handles exit status
I use it mainly for gedit
, evince
, inkscape
etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT
, nohup's exit status is returned instead of zero.
#!/bin/bash
TIMEOUT=0.1
#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "$@" >/dev/null 2>&1 &
NOHUP_PID=$!
#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
MY_PID=$$
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally
#if the command finishes before the above timeout, everything may be just fine or there could have been an error
wait $NOHUP_PID
NOHUP_STATUS=$?
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error $@"
#return the exit status of nohup, whatever it was
exit $NOHUP_STATUS
examples...
>>> run true && echo success || echo fail
success
>>> run false && echo success || echo fail
Error false
fail
>>> run sleep 1000 && echo success || echo fail
success
>>> run notfound && echo success || echo fail
Error notfound
fail
add a comment |
You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session. Use the following command:
nohup -p PID
add a comment |
I prefer:
(applicationName &)
for example:linux@linux-desktop:~$ (chromium-browser &)
Make sure to use parenthesis when type the command!
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.
– redanimalwar
Dec 3 '18 at 4:06
add a comment |
Arguably similar to the answer offered by apolinsky, I use a variant on screen
. The vanilla command is like this
screen bash -c 'long_running_command_here; echo; read -p "ALL DONE:"'
The session can be disconnected with Ctrl ACtrl D and reconnected in the simple case with screen -r
. I have this wrapped in a script called session
that lives in my PATH
ready for convenient access:
#!/bin/bash
#
if screen -ls | awk '$1 ~ /^[1-9][0-9]*.'"$1"'/' >/dev/null
then
echo "WARNING: session is already running (reattach with 'screen -r $1')" >&2
else
exec screen -S "$1" bash -c "$@; echo; echo '--------------------'; read -p 'ALL DONE (Enter to exit):'"
echo "ERROR: 'screen' is not installed on this system" >&2
fi
exit 1
This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
add a comment |
Similarly to other answers posted before, one can transfer a running process to use "screen" retrospectively thanks to reptyr and then close the terminal. The steps are described in this post.
The steps to take are:
- Suspend the process
- Resume the process in the background
- Disown the process
- Launch a screen session
- Find the PID of the process
- Use reptyr to take over the process
add a comment |
protected by slm♦ Jun 7 '18 at 2:39
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
11 Answers
11
active
oldest
votes
11 Answers
11
active
oldest
votes
active
oldest
votes
active
oldest
votes
One of the following 2 should work:
$ nohup redshift &
or
$ redshift &
$ disown
See the following for a bit more information on how this works:
man nohup
help disown
Difference between nohup, disown and & (be sure to read the comments too)
4
The second one (redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?
– Matthew
Nov 13 '10 at 0:52
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly wantnohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with;
(redshift &; disown
)
– Michael Mrozek♦
Nov 13 '10 at 3:14
9
@Michael: Both;
and&
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use&;
in preference to just&
(it works, but it is a bit redundant).
– Chris Johnsen
Nov 13 '10 at 4:29
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
Also,redshift &!
will disown redshift immediately.
– user26112
Apr 21 '13 at 18:30
|
show 4 more comments
One of the following 2 should work:
$ nohup redshift &
or
$ redshift &
$ disown
See the following for a bit more information on how this works:
man nohup
help disown
Difference between nohup, disown and & (be sure to read the comments too)
4
The second one (redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?
– Matthew
Nov 13 '10 at 0:52
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly wantnohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with;
(redshift &; disown
)
– Michael Mrozek♦
Nov 13 '10 at 3:14
9
@Michael: Both;
and&
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use&;
in preference to just&
(it works, but it is a bit redundant).
– Chris Johnsen
Nov 13 '10 at 4:29
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
Also,redshift &!
will disown redshift immediately.
– user26112
Apr 21 '13 at 18:30
|
show 4 more comments
One of the following 2 should work:
$ nohup redshift &
or
$ redshift &
$ disown
See the following for a bit more information on how this works:
man nohup
help disown
Difference between nohup, disown and & (be sure to read the comments too)
One of the following 2 should work:
$ nohup redshift &
or
$ redshift &
$ disown
See the following for a bit more information on how this works:
man nohup
help disown
Difference between nohup, disown and & (be sure to read the comments too)
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Nov 12 '10 at 23:30
Steven DSteven D
32.8k898108
32.8k898108
4
The second one (redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?
– Matthew
Nov 13 '10 at 0:52
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly wantnohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with;
(redshift &; disown
)
– Michael Mrozek♦
Nov 13 '10 at 3:14
9
@Michael: Both;
and&
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use&;
in preference to just&
(it works, but it is a bit redundant).
– Chris Johnsen
Nov 13 '10 at 4:29
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
Also,redshift &!
will disown redshift immediately.
– user26112
Apr 21 '13 at 18:30
|
show 4 more comments
4
The second one (redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?
– Matthew
Nov 13 '10 at 0:52
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly wantnohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with;
(redshift &; disown
)
– Michael Mrozek♦
Nov 13 '10 at 3:14
9
@Michael: Both;
and&
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use&;
in preference to just&
(it works, but it is a bit redundant).
– Chris Johnsen
Nov 13 '10 at 4:29
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
Also,redshift &!
will disown redshift immediately.
– user26112
Apr 21 '13 at 18:30
4
4
The second one (
redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?– Matthew
Nov 13 '10 at 0:52
The second one (
redshift & disown
) worked for me on Ubuntu 10.10. It seems to work fine putting it all on one line. Is there any reason that I shouldn't do this?– Matthew
Nov 13 '10 at 0:52
4
4
@Matthew The first should work fine too, it just doesn't background like the second (you possibly want
nohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with ;
(redshift &; disown
)– Michael Mrozek♦
Nov 13 '10 at 3:14
@Matthew The first should work fine too, it just doesn't background like the second (you possibly want
nohup redshift &
so it does background). And putting the second on one line is fine, although usually you separate with ;
(redshift &; disown
)– Michael Mrozek♦
Nov 13 '10 at 3:14
9
9
@Michael: Both
;
and &
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use &;
in preference to just &
(it works, but it is a bit redundant).– Chris Johnsen
Nov 13 '10 at 4:29
@Michael: Both
;
and &
are command separators and have equal precedence. The only difference is the synchronous versus asynchronous execution (respectively). There is no need to use &;
in preference to just &
(it works, but it is a bit redundant).– Chris Johnsen
Nov 13 '10 at 4:29
4
4
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
good answer, one might add that it would be a good idea to redirect stdout and stderr so that the terminal won't be spammed with debug output
– Kim
Nov 13 '10 at 6:22
11
11
Also,
redshift &!
will disown redshift immediately.– user26112
Apr 21 '13 at 18:30
Also,
redshift &!
will disown redshift immediately.– user26112
Apr 21 '13 at 18:30
|
show 4 more comments
If your program is already running you can pause it with Ctrl-Z
, pull it into the background with bg
and then disown
it, like this:
$ sleep 1000
^Z
[1]+ Stopped sleep 1000
$ bg
$ disown
$ exit
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwidisown
does not disconnect stdout or stderr. Howevernohup
does, as does>/dev/null
(disconnect standard out),2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.
– ctrl-alt-delor
Jul 21 '16 at 22:08
|
show 3 more comments
If your program is already running you can pause it with Ctrl-Z
, pull it into the background with bg
and then disown
it, like this:
$ sleep 1000
^Z
[1]+ Stopped sleep 1000
$ bg
$ disown
$ exit
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwidisown
does not disconnect stdout or stderr. Howevernohup
does, as does>/dev/null
(disconnect standard out),2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.
– ctrl-alt-delor
Jul 21 '16 at 22:08
|
show 3 more comments
If your program is already running you can pause it with Ctrl-Z
, pull it into the background with bg
and then disown
it, like this:
$ sleep 1000
^Z
[1]+ Stopped sleep 1000
$ bg
$ disown
$ exit
If your program is already running you can pause it with Ctrl-Z
, pull it into the background with bg
and then disown
it, like this:
$ sleep 1000
^Z
[1]+ Stopped sleep 1000
$ bg
$ disown
$ exit
answered Nov 13 '10 at 5:36
StefanStefan
11.8k3283123
11.8k3283123
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwidisown
does not disconnect stdout or stderr. Howevernohup
does, as does>/dev/null
(disconnect standard out),2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.
– ctrl-alt-delor
Jul 21 '16 at 22:08
|
show 3 more comments
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwidisown
does not disconnect stdout or stderr. Howevernohup
does, as does>/dev/null
(disconnect standard out),2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.
– ctrl-alt-delor
Jul 21 '16 at 22:08
2
2
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
after disown how can I again read the stdout of the running process?
– Necktwi
May 22 '14 at 10:59
1
1
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
@neckTwi, serverfault.com/questions/55880/…
– Stefan
May 22 '14 at 11:23
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
This didn't work for me for some reason (centos)
– Ian
Apr 17 '15 at 13:42
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
How to kill the process after this procedure?
– Palak Darji
May 2 '16 at 8:30
@necktwi
disown
does not disconnect stdout or stderr. However nohup
does, as does >/dev/null
(disconnect standard out), 2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.– ctrl-alt-delor
Jul 21 '16 at 22:08
@necktwi
disown
does not disconnect stdout or stderr. However nohup
does, as does >/dev/null
(disconnect standard out), 2>/dev/null
(disconnect standard error). It (disown
) disconnects job-control.– ctrl-alt-delor
Jul 21 '16 at 22:08
|
show 3 more comments
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree
, for example when running kate &
in Konsole:
init-+
├─konsole─┬─bash─┬─kate───2*[kate]
│ │ └─pstree
│ └─2*[konsole]
To make the kate
process detached from konsole
when you terminate konsole
, use nohup
with the command, like this:
nohup kate &
After closing konsole
, pstree
will look like this:
init-+
|-kate---2*[kate]
and kate
will survive. :)
An alternative is using screen
/tmux
/byobu
, which will keep the shell running, independent of the terminal.
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
add a comment |
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree
, for example when running kate &
in Konsole:
init-+
├─konsole─┬─bash─┬─kate───2*[kate]
│ │ └─pstree
│ └─2*[konsole]
To make the kate
process detached from konsole
when you terminate konsole
, use nohup
with the command, like this:
nohup kate &
After closing konsole
, pstree
will look like this:
init-+
|-kate---2*[kate]
and kate
will survive. :)
An alternative is using screen
/tmux
/byobu
, which will keep the shell running, independent of the terminal.
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
add a comment |
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree
, for example when running kate &
in Konsole:
init-+
├─konsole─┬─bash─┬─kate───2*[kate]
│ │ └─pstree
│ └─2*[konsole]
To make the kate
process detached from konsole
when you terminate konsole
, use nohup
with the command, like this:
nohup kate &
After closing konsole
, pstree
will look like this:
init-+
|-kate---2*[kate]
and kate
will survive. :)
An alternative is using screen
/tmux
/byobu
, which will keep the shell running, independent of the terminal.
Good answer is already posted by @StevenD, yet I think this might clarify it a bit more.
The reason that the process is killed on termination of the terminal is that the process you start is a child process of the terminal. Once you close the terminal, this will kill these child processes as well. You can see the process tree with pstree
, for example when running kate &
in Konsole:
init-+
├─konsole─┬─bash─┬─kate───2*[kate]
│ │ └─pstree
│ └─2*[konsole]
To make the kate
process detached from konsole
when you terminate konsole
, use nohup
with the command, like this:
nohup kate &
After closing konsole
, pstree
will look like this:
init-+
|-kate---2*[kate]
and kate
will survive. :)
An alternative is using screen
/tmux
/byobu
, which will keep the shell running, independent of the terminal.
answered Dec 5 '12 at 11:31
gertvdijkgertvdijk
7,51253045
7,51253045
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
add a comment |
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
I had problems with the disown methods. This is currently working for me, so upvoting. I also like this because I can tail -f nohup.out to see whats happening, but not worry about my session failing
– Ian
Apr 17 '15 at 13:44
add a comment |
You can run the process like this in the terminal
setsid process
This will run the program in a new session.
As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1) It doesn't print an annoying message aboutnohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output ofjobs
.
– Mikel
Nov 6 '12 at 22:24
add a comment |
You can run the process like this in the terminal
setsid process
This will run the program in a new session.
As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1) It doesn't print an annoying message aboutnohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output ofjobs
.
– Mikel
Nov 6 '12 at 22:24
add a comment |
You can run the process like this in the terminal
setsid process
This will run the program in a new session.
As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux
You can run the process like this in the terminal
setsid process
This will run the program in a new session.
As explained http://hanoo.org/index.php?article=run-program-in-new-session-linux
answered Oct 30 '12 at 5:55
hanoohanoo
33123
33123
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1) It doesn't print an annoying message aboutnohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output ofjobs
.
– Mikel
Nov 6 '12 at 22:24
add a comment |
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1) It doesn't print an annoying message aboutnohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output ofjobs
.
– Mikel
Nov 6 '12 at 22:24
1
1
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
What do you see as the advantages of setsid over nohup?
– itsbruce
Oct 30 '12 at 10:52
1
1
1) It doesn't print an annoying message about
nohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output of jobs
.– Mikel
Nov 6 '12 at 22:24
1) It doesn't print an annoying message about
nohup.out
. 2) It doesn't remain in your shell's job list, so it doesn't clutter the output of jobs
.– Mikel
Nov 6 '12 at 22:24
add a comment |
Though all of the suggestions work well, I've found my alternative is to use screen
, a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name
. Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl+A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl+A and 0 or the newer session by hitting Ctrl+A and 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name
. This will reconnect you to that remote session.
add a comment |
Though all of the suggestions work well, I've found my alternative is to use screen
, a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name
. Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl+A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl+A and 0 or the newer session by hitting Ctrl+A and 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name
. This will reconnect you to that remote session.
add a comment |
Though all of the suggestions work well, I've found my alternative is to use screen
, a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name
. Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl+A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl+A and 0 or the newer session by hitting Ctrl+A and 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name
. This will reconnect you to that remote session.
Though all of the suggestions work well, I've found my alternative is to use screen
, a program that sets up a virtual terminal on your screen.
You might consider starting it with screen -S session_name
. Screen can be installed on virtually all Linux and Unix derivatives. Hitting Ctrl+A and (lower case) C will start a second session. This would allow you to toggle back and forth between the initial session by hitting Ctrl+A and 0 or the newer session by hitting Ctrl+A and 1. You can have up to ten sessions in one terminal. I used to start a session at work, go home, ssh into my work machine, and then invoke screen -d -R session_name
. This will reconnect you to that remote session.
edited Oct 23 '15 at 7:42
G-Man
13.6k93770
13.6k93770
answered Feb 18 '15 at 23:07
apolinskyapolinsky
45038
45038
add a comment |
add a comment |
The shell-only way to do all this is to close stdin and background the command:
command <&- &
Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.
Disadvantage is that you can't do this after the fact.
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
add a comment |
The shell-only way to do all this is to close stdin and background the command:
command <&- &
Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.
Disadvantage is that you can't do this after the fact.
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
add a comment |
The shell-only way to do all this is to close stdin and background the command:
command <&- &
Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.
Disadvantage is that you can't do this after the fact.
The shell-only way to do all this is to close stdin and background the command:
command <&- &
Then it won't quit when you quit the shell. Redirecting stdout is a nice optional thing to do.
Disadvantage is that you can't do this after the fact.
answered Mar 14 '14 at 4:55
w00tw00t
25827
25827
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
add a comment |
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
I tried in ubuntu. Killing terminal also closed the launched process. Any idea on why this might be the case?
– Ashok Koyi
Nov 30 '17 at 10:57
add a comment |
I have a script to:
Run arbitrary commands in the background
Stop them from being killed with the terminal window
Suppress their output
Handles exit status
I use it mainly for gedit
, evince
, inkscape
etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT
, nohup's exit status is returned instead of zero.
#!/bin/bash
TIMEOUT=0.1
#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "$@" >/dev/null 2>&1 &
NOHUP_PID=$!
#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
MY_PID=$$
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally
#if the command finishes before the above timeout, everything may be just fine or there could have been an error
wait $NOHUP_PID
NOHUP_STATUS=$?
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error $@"
#return the exit status of nohup, whatever it was
exit $NOHUP_STATUS
examples...
>>> run true && echo success || echo fail
success
>>> run false && echo success || echo fail
Error false
fail
>>> run sleep 1000 && echo success || echo fail
success
>>> run notfound && echo success || echo fail
Error notfound
fail
add a comment |
I have a script to:
Run arbitrary commands in the background
Stop them from being killed with the terminal window
Suppress their output
Handles exit status
I use it mainly for gedit
, evince
, inkscape
etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT
, nohup's exit status is returned instead of zero.
#!/bin/bash
TIMEOUT=0.1
#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "$@" >/dev/null 2>&1 &
NOHUP_PID=$!
#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
MY_PID=$$
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally
#if the command finishes before the above timeout, everything may be just fine or there could have been an error
wait $NOHUP_PID
NOHUP_STATUS=$?
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error $@"
#return the exit status of nohup, whatever it was
exit $NOHUP_STATUS
examples...
>>> run true && echo success || echo fail
success
>>> run false && echo success || echo fail
Error false
fail
>>> run sleep 1000 && echo success || echo fail
success
>>> run notfound && echo success || echo fail
Error notfound
fail
add a comment |
I have a script to:
Run arbitrary commands in the background
Stop them from being killed with the terminal window
Suppress their output
Handles exit status
I use it mainly for gedit
, evince
, inkscape
etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT
, nohup's exit status is returned instead of zero.
#!/bin/bash
TIMEOUT=0.1
#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "$@" >/dev/null 2>&1 &
NOHUP_PID=$!
#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
MY_PID=$$
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally
#if the command finishes before the above timeout, everything may be just fine or there could have been an error
wait $NOHUP_PID
NOHUP_STATUS=$?
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error $@"
#return the exit status of nohup, whatever it was
exit $NOHUP_STATUS
examples...
>>> run true && echo success || echo fail
success
>>> run false && echo success || echo fail
Error false
fail
>>> run sleep 1000 && echo success || echo fail
success
>>> run notfound && echo success || echo fail
Error notfound
fail
I have a script to:
Run arbitrary commands in the background
Stop them from being killed with the terminal window
Suppress their output
Handles exit status
I use it mainly for gedit
, evince
, inkscape
etc that all have lots of annoying terminal output. If the command finishes before TIMEOUT
, nohup's exit status is returned instead of zero.
#!/bin/bash
TIMEOUT=0.1
#use nohup to run the command, suppressing its output and allowing the terminal to be closed
#also send nohup's output to /dev/null, supressing nohup.out
#run nohup in the background so this script doesn't block
nohup "$@" >/dev/null 2>&1 &
NOHUP_PID=$!
#kill this script after a short time, exiting with success status - command is still running
#this is needed as there is no timeout argument for `wait` below
MY_PID=$$
trap "exit 0" SIGINT SIGTERM
sleep $TIMEOUT && kill $MY_PID 2>/dev/null & #ignore "No such process" error if this exits normally
#if the command finishes before the above timeout, everything may be just fine or there could have been an error
wait $NOHUP_PID
NOHUP_STATUS=$?
#print an error if there was any. most commonly, there was a typo in the command
[ $NOHUP_STATUS != 0 ] && echo "Error $@"
#return the exit status of nohup, whatever it was
exit $NOHUP_STATUS
examples...
>>> run true && echo success || echo fail
success
>>> run false && echo success || echo fail
Error false
fail
>>> run sleep 1000 && echo success || echo fail
success
>>> run notfound && echo success || echo fail
Error notfound
fail
edited Jan 20 '15 at 4:56
answered Feb 15 '14 at 4:12
jozxyqkjozxyqk
376510
376510
add a comment |
add a comment |
You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session. Use the following command:
nohup -p PID
add a comment |
You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session. Use the following command:
nohup -p PID
add a comment |
You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session. Use the following command:
nohup -p PID
You can set a process (PID) to not receive a HUP signal upon logging out and closing the terminal session. Use the following command:
nohup -p PID
edited Feb 18 '16 at 6:05
Anthon
61.5k17107170
61.5k17107170
answered Feb 18 '16 at 5:30
tonytony
513
513
add a comment |
add a comment |
I prefer:
(applicationName &)
for example:linux@linux-desktop:~$ (chromium-browser &)
Make sure to use parenthesis when type the command!
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.
– redanimalwar
Dec 3 '18 at 4:06
add a comment |
I prefer:
(applicationName &)
for example:linux@linux-desktop:~$ (chromium-browser &)
Make sure to use parenthesis when type the command!
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.
– redanimalwar
Dec 3 '18 at 4:06
add a comment |
I prefer:
(applicationName &)
for example:linux@linux-desktop:~$ (chromium-browser &)
Make sure to use parenthesis when type the command!
I prefer:
(applicationName &)
for example:linux@linux-desktop:~$ (chromium-browser &)
Make sure to use parenthesis when type the command!
edited Nov 30 '16 at 7:15
answered Mar 2 '16 at 11:15
daGodaGo
1494
1494
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.
– redanimalwar
Dec 3 '18 at 4:06
add a comment |
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.
– redanimalwar
Dec 3 '18 at 4:06
1
1
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Closing the terminal will kill the process, which exactly what OP (and me, thus coming here) want's to avoid
– gromit190
Nov 14 '16 at 14:39
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
Probably you have prompt command that I've used in my answer without parenthesis, if so closing the terminal will kill the process, otherwise it will NOT happen. I've already edited the solution above to make it clear.
– daGo
Nov 30 '16 at 7:13
work for me, tnx
– noadev
Jun 14 '18 at 22:14
work for me, tnx
– noadev
Jun 14 '18 at 22:14
I am wondering why this got not more upvotes.
nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.– redanimalwar
Dec 3 '18 at 4:06
I am wondering why this got not more upvotes.
nohup
prevents any tty output and I actually just wanted redirect the output to a file and it prevented that so this is the better solution to me.– redanimalwar
Dec 3 '18 at 4:06
add a comment |
Arguably similar to the answer offered by apolinsky, I use a variant on screen
. The vanilla command is like this
screen bash -c 'long_running_command_here; echo; read -p "ALL DONE:"'
The session can be disconnected with Ctrl ACtrl D and reconnected in the simple case with screen -r
. I have this wrapped in a script called session
that lives in my PATH
ready for convenient access:
#!/bin/bash
#
if screen -ls | awk '$1 ~ /^[1-9][0-9]*.'"$1"'/' >/dev/null
then
echo "WARNING: session is already running (reattach with 'screen -r $1')" >&2
else
exec screen -S "$1" bash -c "$@; echo; echo '--------------------'; read -p 'ALL DONE (Enter to exit):'"
echo "ERROR: 'screen' is not installed on this system" >&2
fi
exit 1
This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
add a comment |
Arguably similar to the answer offered by apolinsky, I use a variant on screen
. The vanilla command is like this
screen bash -c 'long_running_command_here; echo; read -p "ALL DONE:"'
The session can be disconnected with Ctrl ACtrl D and reconnected in the simple case with screen -r
. I have this wrapped in a script called session
that lives in my PATH
ready for convenient access:
#!/bin/bash
#
if screen -ls | awk '$1 ~ /^[1-9][0-9]*.'"$1"'/' >/dev/null
then
echo "WARNING: session is already running (reattach with 'screen -r $1')" >&2
else
exec screen -S "$1" bash -c "$@; echo; echo '--------------------'; read -p 'ALL DONE (Enter to exit):'"
echo "ERROR: 'screen' is not installed on this system" >&2
fi
exit 1
This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
add a comment |
Arguably similar to the answer offered by apolinsky, I use a variant on screen
. The vanilla command is like this
screen bash -c 'long_running_command_here; echo; read -p "ALL DONE:"'
The session can be disconnected with Ctrl ACtrl D and reconnected in the simple case with screen -r
. I have this wrapped in a script called session
that lives in my PATH
ready for convenient access:
#!/bin/bash
#
if screen -ls | awk '$1 ~ /^[1-9][0-9]*.'"$1"'/' >/dev/null
then
echo "WARNING: session is already running (reattach with 'screen -r $1')" >&2
else
exec screen -S "$1" bash -c "$@; echo; echo '--------------------'; read -p 'ALL DONE (Enter to exit):'"
echo "ERROR: 'screen' is not installed on this system" >&2
fi
exit 1
This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
Arguably similar to the answer offered by apolinsky, I use a variant on screen
. The vanilla command is like this
screen bash -c 'long_running_command_here; echo; read -p "ALL DONE:"'
The session can be disconnected with Ctrl ACtrl D and reconnected in the simple case with screen -r
. I have this wrapped in a script called session
that lives in my PATH
ready for convenient access:
#!/bin/bash
#
if screen -ls | awk '$1 ~ /^[1-9][0-9]*.'"$1"'/' >/dev/null
then
echo "WARNING: session is already running (reattach with 'screen -r $1')" >&2
else
exec screen -S "$1" bash -c "$@; echo; echo '--------------------'; read -p 'ALL DONE (Enter to exit):'"
echo "ERROR: 'screen' is not installed on this system" >&2
fi
exit 1
This only works when you know in advance you want to disconnect a program. It does not provide for an already running program to be disconnected.
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Mar 29 '16 at 15:10
roaimaroaima
46k758124
46k758124
add a comment |
add a comment |
Similarly to other answers posted before, one can transfer a running process to use "screen" retrospectively thanks to reptyr and then close the terminal. The steps are described in this post.
The steps to take are:
- Suspend the process
- Resume the process in the background
- Disown the process
- Launch a screen session
- Find the PID of the process
- Use reptyr to take over the process
add a comment |
Similarly to other answers posted before, one can transfer a running process to use "screen" retrospectively thanks to reptyr and then close the terminal. The steps are described in this post.
The steps to take are:
- Suspend the process
- Resume the process in the background
- Disown the process
- Launch a screen session
- Find the PID of the process
- Use reptyr to take over the process
add a comment |
Similarly to other answers posted before, one can transfer a running process to use "screen" retrospectively thanks to reptyr and then close the terminal. The steps are described in this post.
The steps to take are:
- Suspend the process
- Resume the process in the background
- Disown the process
- Launch a screen session
- Find the PID of the process
- Use reptyr to take over the process
Similarly to other answers posted before, one can transfer a running process to use "screen" retrospectively thanks to reptyr and then close the terminal. The steps are described in this post.
The steps to take are:
- Suspend the process
- Resume the process in the background
- Disown the process
- Launch a screen session
- Find the PID of the process
- Use reptyr to take over the process
answered May 1 '18 at 20:15
user308879user308879
211
211
add a comment |
add a comment |
protected by slm♦ Jun 7 '18 at 2:39
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
4
Not a default install on all distros, but screen is your friend: en.wikipedia.org/wiki/GNU_Screen
– Zayne S Halsall
Nov 13 '10 at 14:23
To anyone facing the same problem: Remember, that even if you type
yourExecutable &
and the outputs keep coming on the screen andCtrl+C
does not seem to stop anything, just blindly typedisown;
and pressEnter
even if the screen is scrolling with outputs and you can't see what you're typing. The process will get disowned and you'll be able to close the terminal without the process dying.– Nav
Apr 21 '16 at 11:18
You can use screen multiplexer such tmux. It is available via apt-get on ubuntu machines
– Himanshu
May 5 '16 at 11:17