![]() |
There are many different reasons and situations you may want to keep your current terminal activity or execution running. Luckily, there are more than one way of managing the process or application.
nohup and Standard job controlAbout nohupnohup is a command preventing the subsequent executing command from receiving some system Signals such as HANGUP - hence NOHUP = no hangup. It's commonly used with the shell's standard job control since the execution will still occupy the executing prompt, for example, the ampersand to background a task. By default, all the stdout console output is redirected to nohup.out unless you redirect it yourself. This is fine for most situations not requiring user interaction or response. Building and InstallationThe nohup binary is normally included with even the most minimal unix like systems. With Optware, SlugOS or Debian, it's part of the coreutils package. Usage examples nohup cmd & # stdout is redirected to nohup.out
nohup cmd > std.out 2> std.err &
ps -fu username # will show your processes not attached to any shell.
# Important for tracking down nohup processes to kill.
Tips and Suggestions
bash disown$ help disown
disown: disown [-h] [-ar] [jobspec ...]
By default, removes each JOBSPEC argument from the table of active jobs.
If the -h option is given, the job is not removed from the table, but is
marked so that SIGHUP is not sent to the job if the shell receives a
SIGHUP. The -a option, when JOBSPEC is not supplied, means to remove all
jobs from the job table; the -r option means to remove only running jobs.
Additional References
dtachAbout dtachdtach originated as a minimalist alternative to screen. It allows you to spawn a shell or other command into its own detachable pseudo-terminal. It also allows you the ability to share your session with a cohort. It can be used anywhere from large corporate style servers to the lovable NSLU2 Slugs.
Now, you can return to interactive session of `mc`, Vim, or a compile, etc. no sweat. (Try a long compile on the Slug?) In fact, this is probably the most extensive article you'll come across about using dtach. Most people use screen before realizing dtach is just enough - that is if they find out about dtach at all. InstallationIf you are using Optware, just issue the command: If you are using SlugOS, you have two options:
If you're using Debian, If you're using a major distro on your desktop, it should be found in your distro's repository Building and InstallationIf you want to compile, package and install your own version (untried for Slug)
the build on a regular RHES Linux box for personal use was: ./configure; make; strip dtach; cp dtach ~/bin ; # as not to pollute the /usr/bin or /usr/local/bin system using `sudo make install` UsageExample one - a standard, detachable Bash sessionThis example launches a dtach session. If the unix socket exists, attach to it, otherwise create a new session/socket and execute bash. dtach -A /tmp/mydtachsocket -z bash Then to detach from your session you could just close your terminal application or you can press the default Ctrl+\ . Example two - a sharable Bash sessionSay you don't care about a detachable session, but you want to share a Vi session with a co-worker in the same user group. No problem.
Now both you and you co-worker can work together on the same file, seeing the same thing. The best part is, you don't have to restart your session - instant gratification - if you start out using dtach. You can try it out on from a couple of terminals on the same workstation without having to change permission, it's freaky cool. Just Example three - backgrounding like nohupdtach -c /tmp/bgdtach -z myscript Make sure your script or command redirects it's output someplace else for review. It doesn't cache stdout & stderr for you. You would have to attach to see them if not captured. Other Examples or situationsThis list could be really long. It's up to you to try some out. Please add your suggestions and ideas at the end of the page. Many of these are applicable to screen as well.
Gotchas and idiosyncrasies
Tips and Suggestions
Additional References
screen (GNU screen)About GNU screenWhat's there to say? It's the granddaddy of screen multiplexers. It was written years ago in the age of dial-up to allow multiple consoles over a single terminal connection. It's still being actively developed and advanced today. dtach is a 1-to-1 session manager. Screen takes over terminal management. It's highly configurable. Instead of re-hashing the many articles on screen, you can check out some links at the end of this post. And yes, screen allows you to share screen with others. It's a switch and managed differently than dtach. Unfortunately, you may end up with a hand cramp if you're managing several screen screens/tab at a time. Everything is Ctrl+Key CommandKey combo sequence. What's probably more important: I've noticed screen slurping up a lot of memmory (up to 1MB if I've read the numbers correct), and because you'll be running a sh or bash inside it, that takes _another_ 400-500K for every window inside screen.. Be aware of this if you're planning to use this on small-memmory devices like the NSLU2. Installation (much like dtach)If you are using Optware, just issue the command: If you are using SlugOS, you have two options:
If you're using Debian, If you're using a major distro on your desktop, it should be found in your distro's repository Building and InstallationSomeone feel free to point to an article on how to build it from source. UsageSimply invoke: screen It will start screen, load a shell and drop you into it. You can exit it by exiting the shell (just type 'exit', and screen will close too). You can detach it by pressing Ctrl+A D You'll be returned to the non-screened shell, and the process running in screen will continue running in the background. To re-attach to a screen session, enter: screen -R You'll return to your screen session jus where you left it. (however, if there's more than one screen running then it will give you a list of screens to attach to) Inside the 'screen', there are various commands you can use: To create a new screen, press Ctrl+A C. You can do this any number of times. To switch between screens, press Ctrl+A #, where # is 0 through 9. To close a screen, just log out. Note, just because you close 2, doesn't shift 3, 4 & 5 down. #2 is freed up, that's all. Example one - Create a detached screen session. Then attach to it later (from User Contributions)The following screen command will create a new screen session: screen -dmS midnight mc
To attach to this screen, enter: Gotchas and idiosyncrasies(there's more than this)
Tips and Suggestions
Additional References
User Contributed Tips, Examples, URL references, etc.The wall of shame. Feel free to shout out your tips and examples here so we can keep the above article from having 50 tips and examples in each section. Thanks. nohupnohup TipsIn the bit where it says:
I'd like to share how I use the slug to download large files via ftp so that I don't have to have my main computer on.
[1]+ Stopped ftp ftp.desired.server.org
[1]+ ftp ftp.desired.server.org &
If you need to kill the ftp process for whatever reason, list all processes via: ps -ax If the ftp is running and shouldn't be, killall ftp or if it's not responding, killall -9 ftp How I use nohupdtachdtach TipsHow I use dtachscreenscreen Tips
screen -AadR
How I use screen
view ·
edit ·
print ·
history ·
Last edited by MarkStinson.
Based on work by BrianZhou, Fred, bla, asdf, MarkStinson, markstinson, fcarolo, and cbase. Originally by markstinson. Page last modified on June 13, 2008, at 06:44 PM
|