src: add process.ppid
Fixes: https://github.com/nodejs/node/issues/14957 PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
766cd1f59d
commit
3cacd34dc2
@ -1416,6 +1416,19 @@ system platform on which the Node.js process is running. For instance
|
|||||||
console.log(`This platform is ${process.platform}`);
|
console.log(`This platform is ${process.platform}`);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## process.ppid
|
||||||
|
<!-- YAML
|
||||||
|
added: REPLACEME
|
||||||
|
-->
|
||||||
|
|
||||||
|
* {integer}
|
||||||
|
|
||||||
|
The `process.ppid` property returns the PID of the current parent process.
|
||||||
|
|
||||||
|
```js
|
||||||
|
console.log(`The parent process is pid ${process.ppid}`);
|
||||||
|
```
|
||||||
|
|
||||||
## process.release
|
## process.release
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
added: v3.0.0
|
added: v3.0.0
|
||||||
|
@ -2906,6 +2906,12 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void GetParentProcessId(Local<Name> property,
|
||||||
|
const PropertyCallbackInfo<Value>& info) {
|
||||||
|
info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Local<Object> GetFeatures(Environment* env) {
|
static Local<Object> GetFeatures(Environment* env) {
|
||||||
EscapableHandleScope scope(env->isolate());
|
EscapableHandleScope scope(env->isolate());
|
||||||
|
|
||||||
@ -3238,6 +3244,9 @@ void SetupProcessObject(Environment* env,
|
|||||||
READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid()));
|
READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid()));
|
||||||
READONLY_PROPERTY(process, "features", GetFeatures(env));
|
READONLY_PROPERTY(process, "features", GetFeatures(env));
|
||||||
|
|
||||||
|
process->SetAccessor(FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),
|
||||||
|
GetParentProcessId);
|
||||||
|
|
||||||
auto need_immediate_callback_string =
|
auto need_immediate_callback_string =
|
||||||
FIXED_ONE_BYTE_STRING(env->isolate(), "_needImmediateCallback");
|
FIXED_ONE_BYTE_STRING(env->isolate(), "_needImmediateCallback");
|
||||||
CHECK(process->SetAccessor(env->context(), need_immediate_callback_string,
|
CHECK(process->SetAccessor(env->context(), need_immediate_callback_string,
|
||||||
|
16
test/parallel/test-process-ppid.js
Normal file
16
test/parallel/test-process-ppid.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const cp = require('child_process');
|
||||||
|
|
||||||
|
if (process.argv[2] === 'child') {
|
||||||
|
// The following console.log() call is part of the test's functionality.
|
||||||
|
console.log(process.ppid);
|
||||||
|
} else {
|
||||||
|
const child = cp.spawnSync(process.execPath, [__filename, 'child']);
|
||||||
|
|
||||||
|
assert.strictEqual(child.status, 0);
|
||||||
|
assert.strictEqual(child.signal, null);
|
||||||
|
assert.strictEqual(+child.stdout.toString().trim(), process.pid);
|
||||||
|
assert.strictEqual(child.stderr.toString().trim(), '');
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user