linux对于处理复杂和长时间进行人机交互的任务,建议使用使用screen命令,在后台执行。
如何开始screen后台执行任务呢?很简单,执行screen,按回车键进出入子界面,在子界面内执行我们希望长时间执行的任务。
对于系统未安装screen的通过yum install安装一下yum install screen
下面来举例示范一下: 我们切换到oracle用户,然后执行RMAN备份任务,中途我们暂停screen子任务(ctrl+a 再按d键),显示[detached]表示我们已经返回父界面
可以通过screen -ls 查看正在运行的screen任务,并通过screen -r pid 返回screen子界面,通过exit退出screen后台任务(
[screen is terminating])
screen常用的参数
如何开始screen后台执行任务呢?很简单,执行screen,按回车键进出入子界面,在子界面内执行我们希望长时间执行的任务。
对于系统未安装screen的通过yum install安装一下yum install screen
下面来举例示范一下: 我们切换到oracle用户,然后执行RMAN备份任务,中途我们暂停screen子任务(ctrl+a 再按d键),显示[detached]表示我们已经返回父界面
点击(此处)折叠或打开
- [root@indsdb ~]# screen
- [root@indsdb ~]# su - oracle
[oracle@indsdb ~]$ rman target /
Recovery Manager: Release 11.2.0.4.0 - Production on Tue Apr 19 10:38:04 2016
Copyright (c) 1982, 2011, Oracle and/or its affiliates. All rights reserved.
connected to target database: INDSDB (DBID=1797260764)
RMAN> backup database;
Starting backup at 2016-04-19 10:38:30
using target database control file instead of recovery catalog
allocated channel: ORA_DISK_1
channel ORA_DISK_1: SID=670 device type=DISK
channel ORA_DISK_1: starting full datafile backup set
channel ORA_DISK_1: specifying datafile(s) in backup set
input datafile file number=00006 name=/oracle/database/oradata/indsdb.ora
input datafile file number=00010 name=/oracle/database/oradata/indsdb03.ora
input datafile file number=00011 name=/oracle/database/oradata/indsdb04.ora
input datafile file number=00008 name=/oracle/database/oradata/mtstest.ora
input datafile file number=00001 name=/oracle/database/oradata/indsdb/system01.dbf
input datafile file number=00002 name=/oracle/database/oradata/indsdb/sysaux01.dbf
input datafile file number=00009 name=/oracle/database/oradata/indsdb02.ora
input datafile file number=00003 name=/oracle/database/oradata/indsdb/undotbs01.dbf
input datafile file number=00007 name=/oracle/database/oradata/indsdb/ids_interface.ora
input datafile file number=00005 name=/oracle/database/oradata/indsdb/example01.dbf
input datafile file number=00004 name=/oracle/database/oradata/indsdb/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2016-04-19 10:38:31
[detached]
[root@indsdb ~]#
点击(此处)折叠或打开
- [root@localhost ~]# screen -ls
- There is a screen on:
- 3754.pts-0.localhost (Detached)
- 1 Socket in /var/run/screen/S-root.
- [root@localhost ~]# exit
exit
[screen is terminating]
[root@localhost ~]#
点击(此处)折叠或打开
- [root@localhost ~]# screen -help
- Use: screen [-opts] [cmd [args]]
- or: screen -r [host.tty]
- Options:
- -4 Resolve hostnames only to IPv4 addresses.
- -6 Resolve hostnames only to IPv6 addresses.
- -a Force all capabilities into each window's termcap.
- -A -[r|R] Adapt all windows to the new display width & height.
- -c file Read configuration file instead of '.screenrc'.
- -d (-r) Detach the elsewhere running screen (and reattach here).
- -dmS name Start as daemon: Screen session in detached mode.
- -D (-r) Detach and logout remote (and reattach here).
- -D -RR Do whatever is needed to get a screen session.
- -e xy Change command characters.
- -f Flow control on, -fn = off, -fa = auto.
- -h lines Set the size of the scrollback history buffer.
- -i Interrupt output sooner when flow control is on.
- -l Login mode on (update /var/run/utmp), -ln = off.
- -ls [match] or
- -list Do nothing, just list our SockDir [on possible matches].
- -L Turn on output logging.
- -m ignore $STY variable, do create a new screen session.
- -O Choose optimal output rather than exact vt100 emulation.
- -p window Preselect the named window if it exists.
- -q Quiet startup. Exits with non-zero return code if unsuccessful.
- -Q Commands will send the response to the stdout of the querying process.
- -r [session] Reattach to a detached screen process.
- -R Reattach if possible, otherwise start a new session.
- -s shell Shell to execute rather than $SHELL.
- -S sockname Name this session .sockname instead of ...
- -t title Set title. (window's name).
- -T term Use term as $TERM for windows, rather than "screen".
- -U Tell screen to use UTF-8 encoding.
- -v Print "Screen version 4.01.00devel (GNU) 2-May-06".
- -wipe [match] Do nothing, just clean up SockDir [on possible matches].
- -x Attach to a not detached screen. (Multi display mode).
- -X Execute as a screen command in the specified session.
- [root@localhost ~]#
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27039319/viewspace-2083900/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27039319/viewspace-2083900/