GeezerVison is showing github.com — src: add process.ppid · nodejs/node@2d4fca2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/process.md +13Lines changed: 13 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1326,6 +1326,19 @@ system platform on which the Node.js process is running. For instance | 1326 | 1326 | console.log(`This platform is ${process.platform}`); | 1327 | 1327 | ``` | 1328 | 1328 |
| | 1329 | +## process.ppid | | 1330 | +<!-- YAML | | 1331 | +added: REPLACEME | | 1332 | +--> | | 1333 | + | | 1334 | +* {integer} | | 1335 | + | | 1336 | +The `process.ppid` property returns the PID of the current parent process. | | 1337 | + | | 1338 | +```js | | 1339 | +console.log(`The parent process is pid ${process.ppid}`); | | 1340 | +``` | | 1341 | + | 1329 | 1342 | ## process.release | 1330 | 1343 | <!-- YAML | 1331 | 1344 | added: v3.0.0 | |
Collapse file Copy file name to clipboardExpand all lines: src/node.cc +9Lines changed: 9 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -2950,6 +2950,12 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | 2950 | 2950 | } | 2951 | 2951 |
| 2952 | 2952 |
| | 2953 | +static void GetParentProcessId(Local<Name> property, | | 2954 | + const PropertyCallbackInfo<Value>& info) { | | 2955 | + info.GetReturnValue().Set(Integer::New(info.GetIsolate(), uv_os_getppid())); | | 2956 | +} | | 2957 | + | | 2958 | + | 2953 | 2959 | static Local<Object> GetFeatures(Environment* env) { | 2954 | 2960 | EscapableHandleScope scope(env->isolate()); | 2955 | 2961 |
| @@ -3305,6 +3311,9 @@ void SetupProcessObject(Environment* env, | 3305 | 3311 | READONLY_PROPERTY(process, "pid", Integer::New(env->isolate(), getpid())); | 3306 | 3312 | READONLY_PROPERTY(process, "features", GetFeatures(env)); | 3307 | 3313 |
| | 3314 | + process->SetAccessor(FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"), | | 3315 | + GetParentProcessId); | | 3316 | + | 3308 | 3317 | auto need_immediate_callback_string = | 3309 | 3318 | FIXED_ONE_BYTE_STRING(env->isolate(), "_needImmediateCallback"); | 3310 | 3319 | CHECK(process->SetAccessor(env->context(), need_immediate_callback_string, | |
Collapse file Copy file name to clipboard +16Lines changed: 16 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
|