首页 > 系统相关 >【Linux】守护进程后台训练 & screen命令简介

【Linux】守护进程后台训练 & screen命令简介

时间:2023-01-23 10:44:20浏览次数:57  
标签:简介 screen 会话 window session Linux 进程 守护

✨守护进程

如果你通过ssh登录或以ssh为基础的工具软件(比如XShell、PyCharm,VSCode等,可以用这类工具调试,但是最终长时间运行时请以守护进程的方式执行命令)进行远程执行程序时,那么请注意开守护进程来执行程序,避免因为SSH连接中断导致程序终止,遭受不必要的损失。

通过守护进程执行你的程序有多种方式

  1. screen,此外还有常用的tmux(如需安装执行:apt-get update && apt-get install -y tmux)工具,这里不做介绍
  2. jupyterlab的终端
  3. 如果你使用的是Notebook,Notebook断网后日志更新问题请参考JupyterLab文档最下方

✨后台训练

下面介绍通过使用screen命令后台训练

演示环境为macOS(Linux同理)

演示仅为是本机训练,仅为演示screen命令常用操作

实际使用时请先通过ssh连接到服务器再执行以下操作


screen参数介绍

Options:
-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.
-list         or -ls. Do nothing, just list our SockDir.
-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.
-r            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 <pid>.sockname instead of <pid>.<tty>.<host>.
-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.00.03 (FAU) 23-Oct-06".
-wipe         Do nothing, just clean up SockDir.
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

新建会话

screen

创建指定名称会话

screen -S ${SessionName}

列出所有会话

screen -ls


连接到指定会话

screen -r ${Session}


终止守护进程

先连接到会话

使用CTRL + C终止进程

然后使用exit终止守护进程


✨参考及引用

https://www.autodl.com/docs/daemon/


⭐转载请注明出处

本文作者:双份浓缩馥芮白

原文链接:https://www.cnblogs.com/Flat-White/p/17065037.html

版权所有,如需转载请注明出处。

标签:简介,screen,会话,window,session,Linux,进程,守护
From: https://www.cnblogs.com/Flat-White/p/17065037.html

相关文章

  • Linux系统入门-用户身份与文件权限
    用户身份与文件权限现在操作系统具有权限功能用户身份1、管理员UID为02、系统用户UID一般为1-9993、普通用户UID从1000开始创建新用户---useradduseraddeve查看ideve创建......
  • linux c:子进程、僵尸进程与wait/waitpid的实验
       今天咱们一起实验分析一下僵尸进程的产生与解决:1.托管,无僵尸进程-父进程先退出2.产生僵尸进程-子进程先退出3.父进程wait(阻塞),子进程退出1.托管,无僵尸进程-父......
  • 第五十三章 使用 ^SystemPerformance 监视性能 - InterSystems IRIS Linux 平台性能数
    第五十三章使用^SystemPerformance监视性能-InterSystemsIRISLinux平台性能数据报告%SS-使用ALL^%SS命令在运行过程中采集了四个样本。Configuration*......
  • Unix\Linux多线程复健
    线程是程序中完成一个独立任务的完整执行序列(是一个可调度的实体)一个进程可以包含多个线程查看指定进程的线程号:ps-Lfpid进程是CPU分配资源的最小单位,线程是操作系......
  • 开发常用注解简介
    Spring系预备理解bean注入,自动装配首先了解一下IOC操作Bean管理,bean管理是指(1)spring创建对象(2)spring注入属性。当我们在将一个类上标注@Service或者@Controller或@Com......
  • LINUX学习之正则表达式(十二)
    普通正则元字符元字符匹配描述.匹配除了换行符以外的任意单个字符*前导字符出现0次或连续多次.*任意长度字符^行首(以…开头)$行尾(以…结尾)......
  • 1588_AURIX_TC275_PMU简介
    全部学习汇总:​​GreyZhang/g_TC275:happyhackingforTC275!(github.com)​​PMU是编程存储单元的缩写,但是落实到了具体的硬件模块上其实是一个Flash模块。在TC275中,只......
  • Kettle简介
    一、Kettle基本介绍Kettle(现更名为PentahoDataIntegration-Pentaho)是一款国外开源的ETL工具,纯java编写,可以在Window、Linux、Unix上运行,绿色无需安装。它允许你管理来......
  • 【Linux技术专题系列】「必备基础知识」一起探索和实践sftp配置之密钥方式登录
    FTP服务-vsftp协议实现我们常用的是FTP协议,主要是通过VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是VerySecureFTP从此名称可以看出来,编制者的初......
  • 【Linux技术专题系列】「必备基础知识」一起探索和实践sftp配置之密钥方式登录
    FTP服务-vsftp协议实现我们常用的是FTP协议,主要是通过VSFTP是一个基于GPL发布的类Unix系统上使用的FTP服务器软件,它的全称是VerySecureFTP从此名称可以看出来,编制者的......