Reputation: 45
I'm trying to exec a bash shell in nodejs - which I have working except for job control. I'm pretty sure this is because the spawned process is not being set to the process leader. In C, I was able to do this by calling setsid(). In nodejs, I read that the equivalent is setting the option 'setsid: true' when spawning the new process. I did this like so:
var child = spawn('/bin/bash', ['--login'], {stdio: [this.slave, this.slave, this.slave], env: {"TERM": "vt100"}, setsid: true});
However I still get the message "no job control in this shell".
Sample output, after allocating pty ttys002:
bash: no job control in this shell
Amandas-MacBook-Pro:puffshell amanda$ tty
/dev/ttys002
Amandas-MacBook-Pro:puffshell amanda$
Amandas-MacBook-Pro:puffshell amanda$ ps
PID TTY TIME CMD
2055 ttys000 0:00.05 -bash
2158 ttys000 0:00.01 /bin/bash
2170 ttys000 0:00.11 puffd
2171 ttys000 0:00.01 /bin/bash --login
Amandas-MacBook-Pro:puffshell amanda$
So in summary, my questions are:
- is this the correct way to set the new process's session id? And if so, how do I definitively check that it is actually doing that correctly (as it seems to me like it is not - this is the only thing I'd imagine would cause no job control, as the tty command is evidence that the pty was set up correctly).
- If this method won't work, are there any alternatives to setsid() that don't involve downloading a module? I will write a c++ addon if there is not.
Thanks for any help!
Upvotes: 1
Views: 829
Reputation: 23070
What version of node are you using? setsid used to be in the documentation, but was replaced with a detached option.
https://nodejs.org/api/child_process.html#child_process_options_detached
Upvotes: 2