ga('set', 'anonymizeIp', 1);
Categories: LinuxTech Introduce

[Linux] Run program background even if user signed out and out put log files

Share

Tell you how to run programs in linux background and out put log files.

‘nohup’ command + &

Assume that you have a node-js server program namded ‘myServer.js’ and you want to run forever in linux background(means that it will be still running even if you logged out).

Type the following command:
nohup node ./myServer.js &

The nohup command will ignore the "Signal hang up", so even if the user who start the process signed out, the nohup command will keep the process alive and running.

The & make the command run in background.

.out log files

The nohup command will output a nohup.out log file by default.
You can use the following command to output customize .out file.
nohup node ./myServer.js >> ./log/server_nohup.out 2>&1 &
The above command will run myServer.js background and ignore user sign out event. Then output the standard outputs and error outputs to the same file – ./log/server-nohup.out.

Explain:
node ./myServer.js > output.out
Means that the process will save the standard outputs into output.out file. The > output.out is same as 1> output.out.

node ./myServer.js 2> output.out
Means that the process will save the error outputs into output.out file.

node ./myServer.js >> output.out 2>&1
Means that the process will output the error outputs and standard outputs to the same file – ‘output.out’.

Jys

Published by
Jys

Recent Posts

[python] Flask Create RESTful API

This article gi... Read More

3 年 前發表

[Javascript] 新增/刪除JSON中key值

在web訊息交換常會需要對JS... Read More

3 年 前發表

[JAVA] SQL Server Connection

本文介紹JAVA連線SQL s... Read More

3 年 前發表