File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -1373,6 +1373,19 @@ system platform on which the Node.js process is running. For instance
13731373console .log (` This platform is ${ process .platform } ` 
13741374``` 
13751375
1376+ ## process.ppid  
1377+ <!--  YAML
1378+ added: REPLACEME 
1379+ --> 
1380+ 
1381+ *  {integer}
1382+ 
1383+ The ` process.ppid `  property returns the PID of the current parent process.
1384+ 
1385+ ``` js 
1386+ console .log (` The parent process is pid ${ process .ppid } ` 
1387+ ``` 
1388+ 
13761389## process.release  
13771390<!--  YAML
13781391added: v3.0.0 
Original file line number Diff line number Diff line change @@ -3184,6 +3184,12 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) {
31843184}
31853185
31863186
3187+ static  void  GetParentProcessId (Local<Name> property,
3188+                                const  PropertyCallbackInfo<Value>& info) {
3189+   info.GetReturnValue ().Set (Integer::New (info.GetIsolate (), uv_os_getppid ()));
3190+ }
3191+ 
3192+ 
31873193static  Local<Object> GetFeatures (Environment* env) {
31883194  EscapableHandleScope scope (env->isolate ());
31893195
@@ -3517,6 +3523,9 @@ void SetupProcessObject(Environment* env,
35173523                    Integer::New (env->isolate (), GetProcessId ()));
35183524  READONLY_PROPERTY (process, " features" GetFeatures (env));
35193525
3526+   process->SetAccessor (FIXED_ONE_BYTE_STRING (env->isolate (), " ppid" 
3527+                        GetParentProcessId);
3528+ 
35203529  auto  need_immediate_callback_string =
35213530      FIXED_ONE_BYTE_STRING (env->isolate (), " _needImmediateCallback" 
35223531  CHECK (process->SetAccessor (env->context (), need_immediate_callback_string,
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+ } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments