Screen & Tmux tips: Linux Background Runtime program

Source: Internet
Author: User

Popular Introduction:

Screen Simple application:

screen myprogram     // 通过screen启动一个程序, 或者screen -L myprogram: turns on logging to ~/screenlog.0ctr+a 然后再按一下 d   // 使程序在后台运行,即detach-ls           // 列出在screen后台运行的程序,以及ID(例如4491.pts-2.localhost)-r ID         // 恢复运行程序到terminal,例如:screen -r 4491//退出当前screen会话(同 ctrl+a 再按 k),有时候会打开很多screen,可以通过exit退出。

Multi-Window Management:

If you run multiple screens in one terminal, that is, a nested multilayer screen, you ctrl+a 再按 w can view all the screen windows under the current terminal, the * number represents the window in which the current session is located, and then ctrl+a 再按 0~9 you can switch to a corresponding window.

A good article about screen, just read it:
http://www.ibm.com/developerworks/cn/linux/l-cn-screen/


The application of complex points is as follows:

One-off :

When your use is need to detach with the CTRL+A+D before you exit ssh.

Alternatively, if you want to run a process directly with screens you can use

aandfromitanewtheaon logging to ~/screenlog.0

Example

screen -dmSL myalias myscript.sh

You can then either:

Resume later usingscreen -x myalias

Or

Check the log fileless -r ~/screenlog.0

another:

Screen command Example 1:execute a command (or Shell-script), and detach the screen

$ screen unix-command-to-be-executed./unix-shell-script-to-be-executed

Once you ' ve used the "Screen command", you can detach it from the terminal using any one of the following method.

Screen Detach Method 1: Detach the screen usingCTRL+A d

When the command was executing, press followed by-detach the screen CTRL+A d .

Screen Detach Method 2: Detach the screen using -d option

When the command was running in another terminal, type the command as following.

$ screen -d SCREENID

Screen Command Example 2: List all the running screen processes

You can list all the running screens processes using the screen -ls command.

For example:

On Terminal 1 do the following:

$ screen ./myscript.sh

From Terminal 2 Your can view the list of all screens processes. You can also detach it from Terminal 2 as shown below.

ison:    4491.pts-2.localhost    (Attached)1in /var/run/screen/S-i5.
4491.pts-2.localhost   [4491.pts-2.localhost   detached.]

Screen Command Example 3:attach the screens when required

You can attach the screens at anytime by specifying, the screen ID as shown below. You can get the screen ID from the "screen-ls" command output.

$ screen -r 4491.pts-2.FC547

Tmux:

Let's start by understanding some of the elements of Tmux. The main elements of Tmux are divided into three layers:

    • Session a set of windows that is typically used to summarize the same task. The session can have its own name to facilitate switching between tasks. Both detach and attach are session-based, with tmux commands to create a session.
    • Windows has its own number in a single visible window. Created by Tmux in the session C-b+c .
    • Pane panes, which are divided into small blocks of windows. Through the window C-b+" (split horizontally, left and right two pane) or C-b+% (vertically split, up and down two pane).

namely:
Session: A server can contain multiple sessions
Window: A session can contain multiple windows
pane: Panel, a window can contain multiple pane

Shortcut keys at a glance:

tmux  #开启tmux, create a new session:t  Tmux LS  #显示已有tmux列表 (c-b s)  tmux attach -session-t N Span class= "hljs-comment" > #重新连接上第n个session, i.e. attach. Or: Tmux a–t n  c-b C  #创建一个新的窗口  c-b n  #切换到下一个窗口  c-b P  #切换到上一个窗口  c-b l  #最后一个窗口, and the concept of the previous window is not the same yo, Who tried to know  c-b w  #通过上下键选择当前窗口中打开的会话  c-b n  #直接跳到第n个窗口  C-b &  #退出当前窗口 (Kill window while closing all small windows)  c-b x # Close the small window at the current cursor or close the window   
If there is only one

C-b dtemporary disconnect session, i.e. Dettach, screen-like ctrl+a+d (via Tmux LS view session number, e.g. 0, then Tmux attach-session-t 0 re-attach)
C-b "Split out a window
C-b %Split out a window
C-b oSwitch in a small window
C-b(Direction key)
C-b !Creates a new window and maximizes the current small window

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Screen & Tmux tips: Linux Background Runtime program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.