Assume that a rails program is started:
Ruby script/Server
This is usually the case:
Nohup Ruby script/Server &
The error output stream is also directed to the normal output stream:
Nohup Ruby script/Server & 2> 1 &
To record the PID:
Nohup Ruby script/Server & 2> 1 & Echo $! > TMP/PID &
After repeated debugging, the above statement seems inappropriate. The total number of PID values written down is 1 larger than the actual PID, so it is changed:
Nohup Ruby script/Server & Echo $! > TMP/PID & 2> 1 &
That's all.
The above problems were confirmed by colleagues in the C ++ group in the company, but they agreed that adding 2> 1 will not change the process number, which is inconsistent with my actual test.
Kill $ (cat tmp/PID)
The above nohup will be output to the nohup. Out file in the current directory. You can also change it:
Nohup Ruby script/Server>/dev/null & Echo $! > TMP/PID & 2> 1 &