简体   繁体   中英

What if we close the terminal before finishing the command?

Let me explain better. What is gonna happen if I run a command in Linux and before it's done and you could enter another command I close the terminal. Would it still do the command or not?

Generally, you must expect that closing your terminal will hangup your command. But fear not! Linux has a solution for that too!

To ensure that your command completes, use the nohup argument first. Simply place it before whatever you are trying to do:

nohup ./some_program
nohup ./do_a_thing -frx -file input_file.txt
nohup grep "something" giant_list_of_files/* > temp_file.txt

The nohup command stands for "no hangup" and it will ensure that the command you execute continues to run, even if you close your terminal.

It depends on the process and your environment (job control shell options, VNC, etc). But typically, no. The process will get a "hangup" signal (message) from the operating system, and upon receiving that, will quit.

The nohup command, for example, arranges for processes to ignore the hangup signal from the OS. There are many ways to achieve the same result.

I would say it will abort att the status you are in just before the session close.

If you want to be sure to complete the job, you will need to use the nohup command.

http://en.wikipedia.org/wiki/Nohup

Read about nohups and daemons (-d)...

A good link is [link] What's the difference between nohup and a daemon?

值得一看的是screen命令,Screen命令提供了从会话中分离长时间运行的进程(或程序或shell脚本),然后在以后附加它的功能。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM