How to make the Linux process run stably in the background

  
 

We often come across telnet/ssh to log in to a remote Linux server and run some time-consuming tasks. As a result, the task fails midway due to network instability, system timeout, or user logout. So how do you let the command be submitted without being disturbed by the local closed terminal window/network disconnection? Here are some practical examples collected. You can choose different ways to solve this problem for different scenarios.

1. Business Scenario 1:

We know that when a user logs out or the network is disconnected, the terminal will receive a HUP (hangup) signal to shut down all its child processes. Therefore, our solution has two ways: either let the process ignore the HUP signal, or let the process run in a new session to become a child process that does not belong to this terminal.

1. nohup

nohup is undoubtedly the first thing we think of. As the name implies, the purpose of nohup is to have the submitted command ignore the hangup signal. Simply add nohup to the command you want to process, and standard output and standard error will be redirected to the nohup.out file by default. In general, we can add ”&” to put the command into the background at the end, or use ”>filename 2>&1″ to change the default redirect file name.

Show 1:

[root@test ~]# nohup ping www.chinaunix.net &

[1] 3059

nohup: Appending output to `nohup.out’

[root@test ~]# ps -ef

Copyright © Windows knowledge All Rights Reserved