1、linuxscreencommand命令及示例本文包含两部分。第一部分虽然是整理来的英文资料,但平时搜索不容易搜索到,所以还是比较有价值的,是关于多路利用终端软件详解和比较的http:/hyperpolyglot.org/multiplexers,然后把自己不关心的tmux部分删除后,只留下screen的部分。第二部分针对原文命令行参数部分的不足增加了完整的help,并增加了一个sipP测试的例子。本人其实只关心原文的screen command那一列,因为从命令行help无法获取这一部分信息,而我一起在苦苦查找这部分资料,它对以编程的方式控制screen是非常重要的参考,使在无人值守的情况下
2、(如定时或在系统崩溃重新启动后)自动创建一个有多window的screen并启动若干后台测试成为可能。1. Terminologyserver | client | session | window | region | panehow ssh works:When a user logs in to a remote host using ssh, the ssh process contacts an sshd process listening on TCP port 22. The sshd process opens up a new TCP port and forks off a
3、 copy of itself for communicating with the ssh process. The new port and child process are for the exclusive use of the connection being established.The child sshd process authenticates the ssh process, and if it passes it creates a pseudo-terminal. It then forks the remote users shell which becomes
4、 the controlling process for the pseudo-terminal.If the network connection is closed, either explicitly by the ssh process or because of a loss of network connectivity, the child sshd process closes the pseudo-terminal, and this in turn causes the shell to exit.the SIGHUP problem:If the shell had an
5、y process groups running when it exits, they are sent a SIGHUP signal followed by a SIGCONT signal. By default processes exit when they receive SIGHUP. This makes it challenging to run long-running jobs on a remote host when the network connection is unreliable.A simple solution to the SIGHUP proble
6、m is to run each job with nohup. Optionally, shells such as bash and zsh have a disown built-in which can be used on a process that is already running, should the user have neglected to run it with nohup.The fish shell when invoking a process in the background with & sets the signal handling state o
7、f the process to ignore SIGHUP. It will do the same if the process is suspended with Z and then put in the background with bg.Multiplexers offer a solution which protects the shell instead of the job. The user doesnt need to remember to run each job with nohup. As an added benefit any state kept by
8、the shell is preserved.server:The multiplexer server creates pseudo-terminals which are used for running and interacting with programs.Screen and Tmux servers can create multiple pseudo-terminals. The controlling process for each pseudo-terminal is the users shell.client:To see the output of a shell
9、 the user must connect to the multiplexer server with a multiplexer client process.If the multiplexer is being run on a remote machine and the users connection is lost, the server and its terminals and controlling processes persist, but the client process exits.When multiple client processes connect
10、 to the same server they see the same output. This is a way to share a display across computers.session:Multiplexers support multiple sessions. Each multiplexer session has its own set of terminals and controlling processes which it is running. The client must choose a session to attach to, and will
11、 only be able to see the output of the controlling processes in that session. Sessions can be given names to make it easy for the client to choose the correct session.Screen launches a separate server process for each session. Screen servers and clients communicate via named pipes.Tmux by default wi
12、ll only run one server process per user, and this server process can have multiple sessions. A Tmux client and the server communicate via a Unix domain socket in the /tmp directory. The -L option can be used to specify a different socket; a new server is created for each socket.window:Both Screen an
13、d Tmux have entities which they call windows.A Screen window has a single pseudo-terminal and shell. A Tmux window can have multiple pseudo-terminals and shells.Screen windows can share the viewport. The Tmux viewport can only display one window at a time.Both Screen and Tmux windows are numbered st
14、arting from zero.region:Screen can divide the viewport into multiple regions.Screen regions can be empty or they can contain a window. The same window can be displayed in more than one region. When regions share a window their content is identical.Screen regions are stacked on top of each other and
15、extend the full width of the window.pane:Tmux can divide windows into multiple panes.Tmux panes contain a single pseudo-terminal with a shell, and each pseudo-terminal and shell belongs to only one pane.Tmux windows can be divided both horizontally and vertically into panes. Each division can be sub
16、divided further.Tmux panes are numbered.Tmux panes can be moved between mand character (prefix):Multiplexers pass most input on to the shell in the region with focus, but a special command character is used to send commands to the multiplexer.The default command character in Screen is C-a. The keyst
17、rokes which follow C-a are interpreted by Screen instead of being passed to the shell.Tmux calls the command character the prefix and the default value is C-b. The keystrokes following the prefix are interpreted by Tmux instead of being passed to shell.scrollback buffer (history):Screen and Tmux kee
18、p a history of the output of each shell. The maximum length of the output in lines is configurable.Screen calls the history the scrollback buffer.copy/scrollback mode (copy mode):Screen and Tmux support two modes for each region. In default mode, input which is not intercepted by the multiplexer is
19、passed to the shell.When the region is in copy mode the region behaves like a read-only buffer of an editor. The contents are the output of the shell including output that may have scrolled off the top of the region.The keybindings used by Screen in copy/scrollback mode are Vim-style. It is possible
20、 to customize them to be Emacs-style.The Tmux calls copy/scrollback mode simply copy mode. The keybindings are by default Emacs-style.paste buffer:Screen has a single paste buffer.Tmux has multiple paste buffers. The Tmux paste buffers are numbered; the most recent is number zero. Sessions share a c
21、ommon paste buffer history.caption (status line):When a Screen window is split into multiple regions, a caption line is placed at the bottom of each region. When a window contains a single region, Screen by default does not display a caption. The caption, when present, contains information from Scre
22、en. The information that is displayed can be customized.Tmux calls the line at the bottom of a window the status line. By default it is always displayed, though it can be turned off. The status line contains information from Tmux which can be customized.2. Key Bindingssessions | windows | regions |
23、panes | paste buffer | copy modefunctoinC-a shotcutscreen commandhelp?:helpsend prefix to appa:metasuspend multiplexerC-z:suspendshow previous multiplexer messagemC-m:lastmsgsource file-:source filedetachdC-d:detachsessionsfunctionC-a shotcutscreen commandnew session-new named session-switch session
24、-rename session-:sessionname fookill sessionC-:quitwindowsfunctionC-a shotcutscreen commandcreate new windowcC-c:screenswitch to next windownC-nSPACE:nextswitch to previous windowpC-pBACKSPACEh:prevtoggle to last windowC-a:otherselect window n-list windowswC-w:windowsshow current window number and n
25、ameN:numberrenumber current window-move current window to another session-redraw current windowlC-l:redisplaychoose window interactively:windowlist -brename windowA:titleselect window foo:selectclose current windowC-k:killjoin window 1 to current window-join region 0 of window 1 to current window-re
26、gionsfunctionC-a shotcutscreen commandsplit into top and bottom regionsS:splitmove down to next regionTAB:focusmake regions same height-:resize =close current regionX:removeclose all but current regionQ:onlyclear current regionC:clearlog region to file-file is screenlog.NN:logturn off logging-:log o
27、ffmake current region n rows taller/shorter-:resize +n:resize -nmake current region n rows tall-:resize npaste bufferfunctionC-a shotcutscreen commandenter copy modeC-ESC:copypaste most recent buffer-list buffersonly one buffer-choose buffer to paste interactively-write buffer to filewrites to /tmp/
28、screen-exchange:writebuf pathcopy file to buffercopies from /tmp/screen-exchange:readbuf pathcopy modefunctionshotcutscreen commanddefault bindingsVim-styleset markSPACE-copy from mark to point and exit copy modewhen mark is set:SPACE-single column movementalso left right arrowh l-single line moveme
29、ntalso down up arrowj k-beginning of line0-end of line$-forward worde-backward wordb-page upC-b-page downC-f-beginning of bufferg-end of bufferG-search backwards? phrase-search forwards/ phrase-exit copy modeany unbound key also works:ESC-3. Customizationfuncitonconfigurationstartup file/.screenrcsc
30、rollback lengthdefscrollback 2000set prefixhow to set prefix to C-b, with a second C-b to send a C-b to the controlling process:escape BBdefine key bindingbindundefine key binding-set copy/scrollback key binding stylevi bindings by default.When redefining, use vicommands on left of equations:markkey
31、s h=B:l=F:$=Edisable startup messagestartup_message offnumber windows from one-always show status barsplitonly by default:caption alwayscaption splitonlycustomize captioncaption string stringcaption escapesfunctionconfigurationshell outputfirst arg is an identifier referenced by the caption string;the second and th
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2