Skip to content

Commit c31e307

Browse files
fix(ext/node): export ppid (#31137)
Fix #31135
1 parent 552cb3d commit c31e307

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

ext/node/polyfills/process.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export let arch = "";
7575
export let platform = isWindows ? "win32" : ""; // initialized during bootstrap
7676

7777
export let pid = 0;
78+
export let ppid = 0;
7879

7980
let stdin, stdout, stderr;
8081

@@ -1027,7 +1028,7 @@ internals.__bootstrapNodeProcess = function (
10271028
arch = arch_();
10281029
platform = isWindows ? "win32" : Deno.build.os;
10291030
pid = Deno.pid;
1030-
1031+
ppid = Deno.ppid;
10311032
initializeDebugEnv(nodeDebug);
10321033

10331034
if (getOptionValue("--warnings")) {

tests/unit/process_test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,3 +677,25 @@ Deno.serve({ signal: ac.signal }, () => new Response("Hello World"));
677677
await Deno.remove(tempDir);
678678
},
679679
);
680+
681+
Deno.test({
682+
name: "process.ppid matches parent process",
683+
permissions: { run: true, read: true },
684+
ignore: Deno.build.os === "windows",
685+
async fn() {
686+
const command = new Deno.Command(Deno.execPath(), {
687+
args: [
688+
"eval",
689+
"import { ppid } from 'node:process'; console.log(ppid);",
690+
],
691+
stdout: "piped",
692+
});
693+
694+
const { stdout } = await command.output();
695+
const stdoutPpid = parseInt(
696+
new TextDecoder().decode(stdout).trim(),
697+
);
698+
699+
assertEquals(stdoutPpid, Deno.pid);
700+
},
701+
});

0 commit comments

Comments
 (0)