Note that the process remains even after logging out with SSH

Introduction

This is a memo on how to keep the process after logging out when connecting with SSH. Basically, you can do what you want to do.

$content of the nohup command> out.log &

Example

$ nohup echo "very very heavy task" > out.log &

Doing this will create a ʻout.log` file in the calendar directory and save the output.

out.log


very very heavy task

Functionalization

The main is from here. The previous command is a bit long, so register it as a function.

The shell I'm using is zsh, so add the following to ~ / .zshrc. For bash, add it to ~ / .bashrc.

.zshrc


background () {
    nohup ${@:1} > out.log &
}

Save the content and apply your changes.

$ source ~/.zshrc

You can now run it in the background by simply prefixing the process you want to run with background.

$ background echo "very very heavy task"

It doesn't matter how many arguments you have.

$ background python takes_many_args.py foo bar --arg3 1234 --arg4 abcd

Recommended Posts

Note that the process remains even after logging out with SSH
Problem that even if Pool.close () is done with Python multiprocessing, the process remains paused and the memory increases steadily.
Kill the process with sudo kill -9