| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f82d3e4 commit 41937be
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1416,6 +1416,19 @@ system platform on which the Node.js process is running. For instance | |||
| 1416 | 1416 | console.log(`This platform is ${process.platform}`); | |
| 1417 | 1417 | ``` | |
| 1418 | 1418 | ||
| 1419 | + ## process.ppid | ||
| 1420 | + <!-- YAML | ||
| 1421 | + added: REPLACEME | ||
| 1422 | + --> | ||
| 1423 | + | ||
| 1424 | + * {integer} | ||
| 1425 | + | ||
| 1426 | + The `process.ppid` property returns the PID of the current parent process. | ||
| 1427 | + | ||
| 1428 | + ```js | ||
| 1429 | + console.log(`The parent process is pid ${process.ppid}`); | ||
| 1430 | + ``` | ||
| 1431 | + | ||
| 1419 | 1432 | ## process.release | |
| 1420 | 1433 | <!-- YAML | |
| 1421 | 1434 | added: v3.0.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3233,6 +3233,12 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | |||
| 3233 | 3233 | } | |
| 3234 | 3234 | ||
| 3235 | 3235 | ||
| 3236 | + static void GetParentProcessId(Local<Name> property, | ||
| 3237 | + const PropertyCallbackInfo<Value>& info) { | ||
| 3238 | + info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid())); | ||
| 3239 | + } | ||
| 3240 | + | ||
| 3241 | + | ||
| 3236 | 3242 | static Local<Object> GetFeatures(Environment* env) { | |
| 3237 | 3243 | EscapableHandleScope scope(env->isolate()); | |
| 3238 | 3244 | ||
@@ -3565,6 +3571,9 @@ void SetupProcessObject(Environment* env, | |||
| 3565 | 3571 | READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid())); | |
| 3566 | 3572 | READONLY_PROPERTY(process, "features", GetFeatures(env)); | |
| 3567 | 3573 | ||
| 3574 | + process->SetAccessor(FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"), | ||
| 3575 | + GetParentProcessId); | ||
| 3576 | + | ||
| 3568 | 3577 | auto need_immediate_callback_string = | |
| 3569 | 3578 | FIXED_ONE_BYTE_STRING(env->isolate(), "_needImmediateCallback"); | |
| 3570 | 3579 | CHECK(process->SetAccessor(env->context(), need_immediate_callback_string, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,16 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cp = require('child_process'); | ||
| 5 | + | ||
| 6 | + if (process.argv[2] === 'child') { | ||
| 7 | + // The following console.log() call is part of the test's functionality. | ||
| 8 | + console.log(process.ppid); | ||
| 9 | + } else { | ||
| 10 | + const child = cp.spawnSync(process.execPath, [__filename, 'child']); | ||
| 11 | + | ||
| 12 | + assert.strictEqual(child.status, 0); | ||
| 13 | + assert.strictEqual(child.signal, null); | ||
| 14 | + assert.strictEqual(+child.stdout.toString().trim(), process.pid); | ||
| 15 | + assert.strictEqual(child.stderr.toString().trim(), ''); | ||
| 16 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments