[PYTHON] [Nohup] Execution even if the terminal is turned off

Write code that allows the program to run even if you turn off the terminal.

How to use nohup

nohup (execution code) & You can use nohup with. Below is an example of executing ./a.out.

C:>nohup ./a.out &

The output is written to nohup.out. Once you type the command, execution continues even if you turn off the terminal.

Also, if you want to specify a specific output file, nohup (execution code)> (output file) & Is. An execution example is written below. Write the output of ./a.out to out.txt.

C:>nohup ./a.out >out.txt &

When to end the execution in the middle

ps x After kill (PID) do. An example is written below.

C:>nohup ./a.out &
C:>ps x
  PID TTY      STAT   TIME COMMAND
 5915  --      --     -:-- ./a.out
C:>kill 5915

By doing as above, the execution ends in the middle.

use nohup for python

The method is as follows.

C:>nohup python a.py &

The above example is running a.py.

Or as follows.

C:>nohup python a.py >a.txt &

The above example writes the output of a.py to a.txt.

Recommended Posts

[Nohup] Execution even if the terminal is turned off
Determine if the string is formatable
Determine if the library is installed.
Determine if the gold coin is genuine
Verbose is not turned off in LightGBM
Even if the development language is changed to python3 in Cloud9, version 2 is displayed in python --version
What to do if (base) is displayed at the beginning of the Mac terminal
Python --If statement judgment behavior under multiple conditions (even though the order is different)