Uh oh!
There was an error while loading. Please reload this page.
lib: allow custom names for spawned processes - #7696
Conversation
There was a problem hiding this comment.
Perhaps this should be a bit more specific, like typeof options.name === 'string'.
32435ca to
46f188aCompareThere was a problem hiding this comment.
Better to be use common.mustCall to wrap the callback function
46f188a to
1489f88CompareLGTM. CI Run: https://ci.nodejs.org/job/node-test-pull-request/3277/ Edit: Changes look LGTM. We can still hear from others how useful they think this feature would be. |
There was a problem hiding this comment.
I'd be curious to see if this works on SmartOS. IIRC, SmartOS does not support changing process.title
Yea, looks like tests are failing on Windows and SmartOS |
1489f88 to
5fd63e8Compareppannuto
commented
Jul 13, 2016
Interesting. It appears that there's no mechanism to change the process name on Windows ( http://stackoverflow.com/questions/23783985/set-child-process-name-in-windows ). I've added a note to the documentation that this isn't supported on all platforms and added check that skips this test for Windows and SunOS. |
5fd63e8 to
2d72e34Compareevanlucas
commented
Jul 13, 2016
I do think we should be cautious about adding features that are not supported on all platforms. |
2d72e34 to
df6140dComparesaghul
commented
Jul 13, 2016
IMHO this is not the right way to do it. Node already supports Now, if you want to do that after spawning a process you'd need to run that code in the child. A quick idea would be to have a Please don't follow this blindly, maybe there is a better option. I'd go for actually not doing anything. If you want your workers to have a different process title set some WORKER_NAME env variable and call |
cjihrig
commented
Jul 13, 2016
I agree with both @evanlucas and @saghul |
ppannuto
commented
Jul 13, 2016
Perhaps this is starting to evolve into a nomenclature issue then. My personal motivation was controlling process name, but in general, the ability to control the This patch would eliminate hacky-er things such as https://github.com/andrewffff/child_process_with_argv0 or needless intermediaries like https://github.com/andrep/argv0 Would this be more amenable as an option named |
saghul
commented
Jul 13, 2016
I don't have all platforms to test right now, but are you certain about that? |
ppannuto
commented
Jul 13, 2016
@saghul on my OS X laptop for example: |
I should qualify that as "often limited" or "sometimes limited", it's not universally limited (i.e. Linux always allows 16 characters IIRC) |
As for having the workers change their process title, that is explicitly against my current goals which is to not have to modify the workers at all (i.e. they shouldn't know they're being run by a runner service and not being invoked directly, nor more importantly should a service need to be modified to be supported by this runner). |
@ppannuto I think it’s still the length of the entire argv array that counts, because that’s the space that’s available for it. @saghul Keep in mind that this applies not only to Node.js child processes. I have actually been wondering why Node.js doesn’t support setting Also, that specifying |
ppannuto
commented
Jul 13, 2016
@addaleax you are correct that it's full I'll update the PR to call the option |
addaleax
commented
Jul 13, 2016
That does sound better to me, yes. |
ppannuto
commented
Jul 29, 2016
@jasnell think I got everything. Lmk if anything else needs to change. |
addaleax
commented
Jul 29, 2016
There was a problem hiding this comment.
s/_Note:/_Note*:
For this one and the next. :-)
There was a problem hiding this comment.
Every other "Note" in the file currently italicizes the whole note ( https://github.com/nodejs/node/blame/master/doc/api/child_process.md#L26, https://github.com/nodejs/node/blame/master/doc/api/child_process.md#L39, https://github.com/nodejs/node/blame/master/doc/api/child_process.md#L188 etc). I'm happy to change this one instance if you want, but should it really be inconsistent with the rest of the file?
There was a problem hiding this comment.
Ok, no worries. I'll go through and fix those in a separate PR :-)
jasnell
commented
Aug 1, 2016
Awesome... thank you @ppannuto. I left a couple more comments but I think this is just about ready to go! |
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - nodejs#7434 - nodejs#7449 - nodejs#7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0`
In some cases it useful to control the value of `argv[0]`, c.f. - https://github.com/andrewffff/child_process_with_argv0 - https://github.com/andrep/argv0 This patch adds explicit support for setting the value of `argv[0]` when spawning a process.
d361830 to
c9880e3Compareppannuto
commented
Aug 1, 2016
Updated. I didn't currently change the |
jasnell
commented
Aug 4, 2016
Thank you! LGTM! |
jasnell
commented
Aug 4, 2016
addaleax
commented
Aug 8, 2016
New new CI (that last one failed on Windows): https://ci.nodejs.org/job/node-test-commit/4447/ |
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - #7434 - #7449 - #7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0` PR-URL: #7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
In some cases it useful to control the value of `argv[0]`, c.f. - https://github.com/andrewffff/child_process_with_argv0 - https://github.com/andrep/argv0 This patch adds explicit support for setting the value of `argv[0]` when spawning a process. PR-URL: #7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
addaleax
commented
Aug 8, 2016
For historical and other reasons, node overwrites `argv[0]` on startup. See - 2c6f79c, - #7434 - #7449 - #7696 For cases where it may be useful, save the original value of `argv[0]` in `process.argv0` PR-URL: #7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
In some cases it useful to control the value of `argv[0]`, c.f. - https://github.com/andrewffff/child_process_with_argv0 - https://github.com/andrep/argv0 This patch adds explicit support for setting the value of `argv[0]` when spawning a process. PR-URL: #7696 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
Notable changes: * build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) #7983 and #7576 * child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) #7811 and #7838 * child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) #7696 * fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) #7942 * repl: The REPL now supports editor mode. (Prince J Wesley) #7275 * util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) #8013 Refs: #8020 PR-URL: #8070
Notable changes: * build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) #7983 and #7576 * child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) #7811 and #7838 * child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) #7696 * fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) #7942 * repl: The REPL now supports editor mode. (Prince J Wesley) #7275 * util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) #8013 Refs: #8020 PR-URL: #8070
Notable changes: * build: zlib symbols and additional OpenSSL symbols are now exposed on Windows platforms. (Alex Hultman) nodejs#7983 and nodejs#7576 * child_process, cluster: Forked child processes and cluster workers now support stdio configuration. (Colin Ihrig) nodejs#7811 and nodejs#7838 * child_process: argv[0] can now be set to arbitrary values in spawned processes. (Pat Pannuto) nodejs#7696 * fs: fs.ReadStream now exposes the number of bytes it has read so far. (Linus Unnebäck) nodejs#7942 * repl: The REPL now supports editor mode. (Prince J Wesley) nodejs#7275 * util: inspect() can now be configured globally using util.inspect.defaultOptions. (Roman Reiss) nodejs#8013 Refs: nodejs#8020 PR-URL: nodejs#8070
gibfahn
commented
Feb 16, 2017
@MylesBorins is there a reason this was never backported to v4? |
MylesBorins
commented
Feb 16, 2017
@gibfahn it was never brought up. Semver minors need to be proposed |
gibfahn
commented
Feb 17, 2017
@MylesBorins okay, didn't realise that. Is this how I propose that it be backported? |
Checklist
make -j4 test(UNIX), orvcbuild test nosign(Windows) passesAffected core subsystem(s)
lib/child_process.jsDescription of change
Add a
nameparameter to theoptionsaccepted bychild_process.spawnthat sets the spawned process name (argv[0])to a custom value. The default behavior is unchanged if a
nameparameter is not supplied.
It is useful to be able to set the name of a process you are spawning.
One motivating example is an application runner service that spawn
several other node applications. Instead of showing up as 20 different
nodeprocesses, the application runner can give them meaningful names.While child processes can write
process.titleto change their name,this has two limitations:
argv[0]in practice