当前位置:网站首页>Use the nohup command to mount the program and execute it in the background
Use the nohup command to mount the program and execute it in the background
2022-04-22 04:08:00 【Long life】
1. Preface
- In the use of
sshWhen connecting to a remote server , We can manage the server remotely , Execute background command at remote terminal . however , If you log out before the command is executed , The execution of this command will be interrupted . - Sometimes , We want to log out , But keep the program running . For example, when using remote server to train deep learning model , We don't want to stay connected to the server all the time
- We use
nohupCommand can solve this problem
2.nohup
2.1. Basic usage
[root@localhost ~]# nohup [ command ] &
nohupyes no hangup Abbreviation , It means don't hang up , That is, the program does not exit . This command will Make the program ignoreSIGHUPThe signal , Ensure that the program can run normally .SIGHUPA signal is a signal sent to the process it is associated with when the terminal is terminated , When the process receives this signal, it will stop running . So if you don't want the process to be killed by this signal , You can ignore this signal . andnohupThat's what the order does , Keep the process free shell The impact of closure .- meanwhile ,
nohupAfter execution , Will produce filesnohup.out, The result of executing a programstdout/stderrRedirect to this file . In the current directory , If the current directory is not writable , Then it is automatically saved to the user executing the commandhomeUnder the table of contents , for examplerootIf so, keep it in/root/Next .
- meanwhile ,
&Is to put the command in the background . Putting the program in the background means , We no longer interact with it . This command will Make the program ignoreSIGINTThe signal , We use itctrl C, It will not affect the operation of the program .&It doesn't redirectstdout/stderr, So if the program has any output or produces an error , Will be displayed directly on the terminal .
- [ command ] It is the command we input when we execute the program normally , such as :
python train.py
2.2. Example
nohup python train.py &
- perform
train.pyProgram , Put it in the background , And ignoreshellClose the givenSIGUPInstructions python train.pyNamely[ command ]
2.3. Redirect output
2.3.1. command :command > /dev/null 2>&1 &
>It's the output symbol , Where is the redirect1yesstdoutstandard output , The system default is 1. therefore> hello.txtEquate to1 > hello.txt2yesstderrThe standard error&Is equivalent to ,2>&1, Express ,stderrRedirect the output of to andstdoutThe same position
2.3.2. Program test.py
print('hello world')
p # Intentional error writing
2.3.3. Carry out orders
-
python test.py > hello.txt 2>&1-
hello.txtThe content in- You can see , The output and errors are relocated to
hello.txtin
hello world Traceback (most recent call last): File "/home/nsy/detection/yolov5-master/nsy_demo.py", line 2, in <module> p NameError: name 'p' is not defined - You can see , The output and errors are relocated to
-
-
python test.py > hello.txt-
hello.txtThe content in- You can see , Only the output is relocated to
hello.txtin
hello world- The error message is output at the terminal ( Default ), Without being relocated
- You can see , Only the output is relocated to
-
-
We can use the relocation command with the suspend command
nohup python test.py > hello.txt 2>&1 &
2.4. Terminate the process
nohup Combination of orders & Symbols enable processes to run in the background , Even if the terminal is turned off, it will not be affected . At this time , If you want to terminate the process , How to operate ?
-
The simplest is to use
killcommandkill Process number -
How to find the corresponding process
pidWell ?-> Usepscommandps aux | grep The program name. such asps aux | grep train.py- After finding the process number , Use
kill PIDThat's it
- After finding the process number , Use
版权声明
本文为[Long life]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220400582054.html
边栏推荐
- Do447ansible tower navigation
- Ronglian Qimo empowers enterprises with intelligent services and redefines the value of customer service
- oracle连接数据库增删改查
- pytorch使用profiler对模型性能分析时报错
- Tencent CSIG interview brief (passed)
- . net debugging: use visual studio to debug dump files
- 你的指针学到什么层次了?8个指针题目让你加深对指针的理解(下)-O-
- [recent force buckle] sum of two numbers + same tree
- RF and microwave design software
- 专家有料 | 张祖优:腾讯云DevSecOps实践与开源治理探索
猜你喜欢

Autodesk Genuine Service2020删除

Tutorial - sumolympics

【机器学习】长短时记忆网络(LSTM)

. net debugging: use visual studio to debug dump files

English | Day11, 12 x sentence true research daily sentence (meaning group)

Leetcode1615. Maximum network rank (medium)

均线双边对锁策略原理

Redis database

2022-04-21:给定一个包含 [0,n) 中不重复整数的黑名单 blacklist, 写一个函数从 [0, n) 中返回一个不在 blacklist 中的随机整数, 对它进行优化使其尽量少调用系

Go gin framework configuration log output to file
随机推荐
Web page performance optimization
【Taro开发】-全局自定义导航栏适配消息通知框位置及其他问题(十四)
How to generate PCB real-time snapshot in 3D in Ad
Where is the whole house intelligence that Huawei, Haier Zhijia and Xiaomi are all doing?
小程序 关于分包
Ivorysql 1.2 has come
. net 20th anniversary learning challenge Net mobile application
记一次云服务器配置mysql 远程连接失败的解决方案
Convenience stores are crazy: convenience bee, Rosen and Yijie "fierce battle"
shell编程
Optimisation des performances des pages Web
[golang] force buckle leetcode - 657 Whether the robot can return to the origin (simulation)
教程——sumolympics
Why is Nacos so strong
解决Flutter中ThemeData.primaryColor在AppBar等组件中不生效
Shell programming
Do447ansible tower navigation
Alibaba cloud EMAS product dynamics in March
头歌答案(字符串基本操作)
Leetcode1615. Maximum network rank (medium)