Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to get the ppid of a process? #14957

Closed
chenminhua opened this issue Aug 21, 2017 · 5 comments
Closed

how to get the ppid of a process? #14957

chenminhua opened this issue Aug 21, 2017 · 5 comments
Labels
feature request Issues that request new features to be added to Node.js. libuv Issues and PRs related to the libuv dependency or the uv binding. process Issues and PRs related to the process subsystem.

Comments

@chenminhua
Copy link

I want to let child process know if it's parent was killed, so I hope the child process can get it's ppid.
If ppid == 1, then i can know the parent has died.

But process module seems not having this prop or method

@mscdex
Copy link
Contributor

mscdex commented Aug 21, 2017

This feature request would most likely have to be submitted to the libuv issue tracker as it would need to be added there first. Be aware though, Windows doesn't really have the same kind of support for parent pids like *nix does, in that you can only get the original parent process id (which may/may not have been assigned to another process if the original parent process has since died).

@mscdex mscdex added feature request Issues that request new features to be added to Node.js. libuv Issues and PRs related to the libuv dependency or the uv binding. process Issues and PRs related to the process subsystem. labels Aug 21, 2017
@bnoordhuis
Copy link
Member

bnoordhuis commented Aug 21, 2017

process.pid is implemented directly in node.js (src/node.cc), it doesn't go through libuv. I'm okay with adding a process.ppid property, I can see no reason not to.

@bnoordhuis bnoordhuis removed the libuv Issues and PRs related to the libuv dependency or the uv binding. label Sep 6, 2017
@jayproulx
Copy link

Depending on your need, this is working for me, though I'm not looking for a specific PPID, I'm looking for a "stable" PPID that I can use for a "session" across multiple CLI commands. This may be the proper PPID for the current process, however, I think I saw that this was still a child process of bash.

var ppid = (require('child_process').execSync(ps -p ${process.pid} -o ppid=) + '').split('\n')[0];

@cjihrig
Copy link
Contributor

cjihrig commented Oct 30, 2017

@bnoordhuis the ppid implementation is kind of ugly on Windows. We happen to already have it in libuv though. Would you be opposed to me exposing it from there and using it here?

cjihrig added a commit to cjihrig/libuv that referenced this issue Nov 1, 2017
Refs: nodejs/node#14957
PR-URL: libuv#1610
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
@cjihrig
Copy link
Contributor

cjihrig commented Nov 1, 2017

This will be available in the next libuv release, at which point I'll open a PR to expose it in Node.

@tniessen tniessen added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Nov 1, 2017
@cjihrig cjihrig mentioned this issue Nov 6, 2017
4 tasks
cjihrig added a commit to cjihrig/node that referenced this issue Nov 10, 2017
Fixes: nodejs#14957
PR-URL: nodejs#16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this issue Nov 13, 2017
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 15, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 16, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Jan 17, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 11, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 12, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue Feb 13, 2018
Fixes: #14957
PR-URL: #16839
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. libuv Issues and PRs related to the libuv dependency or the uv binding. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

No branches or pull requests

6 participants