Tuesday, October 14, 2014

Lesson 34: running script with nohup command

Besides using cron, there's a way to run a job in the background even after you logout from your session. You just need to add 'nohup' in the command you run.
For example in my own shell session, i just run this command:
[smlfes@jkt-fes opt]$ nohup sh demona.sh > custom-out.log &
[1] 102647
102647 is the pid(process id) of the process you just created, or if you forget the pid you can just use this command to grep the pid:

[smlfes@jkt-fes opt]$ ps -ef | grep demona.sh
smlfes   100209  98441  0 15:14 pts/2    00:00:00 vim demona.sh
smlfes   102647 101788  0 17:40 pts/3    00:00:00 sh demona.sh
smlfes   102725 101788  0 17:44 pts/3    00:00:00 grep demona.sh

If you want to kill the background process, just use the command
kill -9 102647

No comments:

Post a Comment