• use the Unix nohup command to start jobs that continue to live after you close the terminal window in which they were started. For example, suppose that you have a javascript file named "hw5.js" for node.js for homework 5. To start this using nohup
                        nohup node hw5.js &
                    
  • If I start job with "nohup" from a terminal running in VSC, when that terminal dies the nohup job dies also. This is NOT suppose to happen; I do not know why it happens. Two possibilities:
    1. if you are using nohup, always do so in a terminal window that is NOT running within VSC -- this is the approach I use
    2. try the following instead of nohup
                              node hw5.js > logfile.txt 2> errlogfile.txt & disown $!
                                              
      This may work; I have not tested (The $! syntax is a special variable that represents PID of last executed command.)
  • If you start a "nohup" job in a regular terminal window, be sure to exit the ssh session before closing terminal window. If you close the terminal window without exiting ssh, you end up with the same problem as nohup with VSC. Namely, the nohup session will die. (Is this issue related to the nohup in VSC problem? Almost certainly. How? Why? I do not know.)
  • To kill a process you started using nohup you first need to get the "process number". To do so use the following Unix command
                        ps -ef | grep $USER | grep node
                    
    This will give you a listing of all of your running node.js jobs. For instance
    gtowell   696622       1  0 Jan19 ?        00:00:02 node app5.js
    gtowell   780122       1  0 Jan20 ?        00:00:01 node app6.js
    gtowell   816188  816044  0 10:32 pts/0    00:00:00 grep --color=auto node
                
    The process number is in the second column. So to kill the node process I started on Jan 19, I would enter
                    kill -9 696622