1

I have a nodeJS command line script which interacts with a website using phantomJS via casperJS/spookyJS. A redirect event is stopping my process from working correctly. How would I respond to the redirect, spawn a new process and kill the process which has been redirected?

e.g:

spooky.on('navigation.requested', function(url, navigationType, navigationLocked, isMainFrame){
    if (url.toString().match(/(http:\/\/url(.|\n)to(.|\n)match\/client\/authentication\/login)/i)) {
        utils.log('redirect happened');
        //get my own process id, launch a new process, get that id.
        //kill this id?
    }
});

How would I:

  • Get the process Id of the currently running node process (the one running the above code - process A)?
  • Spawn a new node process (process B) which would be independent of process A
  • Kill Process A

Process B should continue to run even when process A has terminated. Would I need a third node process (C) to manage process A and B?

codecowboy
  • 9,835
  • 18
  • 79
  • 134

1 Answers1

0

use 'detached' option in child_process.spawn() You may also want to detach tty from process (use nohup utility)

Andrey Sidorov
  • 24,905
  • 4
  • 62
  • 75
  • Thanks. If I kill the parent process, will the child process continue to run? – codecowboy Feb 23 '14 at 14:17
  • yes: `If the detached option is set, the child process will be made the leader of a new process group. This makes it possible for the child to continue running after the parent exits.` – Andrey Sidorov Feb 23 '14 at 20:21