Skip to content

Commit d47cb9a

Browse files
cjihriggibfahn
authored andcommitted
src: use uv_os_getpid() to get process id
This commit uses the new uv_os_getpid() method to retrieve the current process id. PR-URL: #17415 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Khaidi Chu <[email protected]>
1 parent dea44b9 commit d47cb9a

File tree

5 files changed

+6
-23
lines changed

5 files changed

+6
-23
lines changed

src/env.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void Environment::PrintSyncTrace() const {
119119
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
120120

121121
fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
122-
GetProcessId());
122+
uv_os_getpid());
123123

124124
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
125125
Local<StackFrame> stack_frame = stack->GetFrame(i);

src/inspector_agent.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int StartDebugSignalHandler() {
110110
CHECK_EQ(0, pthread_attr_destroy(&attr));
111111
if (err != 0) {
112112
fprintf(stderr, "node[%u]: pthread_create: %s\n",
113-
GetProcessId(), strerror(err));
113+
uv_os_getpid(), strerror(err));
114114
fflush(stderr);
115115
// Leave SIGUSR1 blocked. We don't install a signal handler,
116116
// receiving the signal would terminate the process.
@@ -145,7 +145,7 @@ static int StartDebugSignalHandler() {
145145
DWORD pid;
146146
LPTHREAD_START_ROUTINE* handler;
147147

148-
pid = GetCurrentProcessId();
148+
pid = uv_os_getpid();
149149

150150
if (GetDebugSignalHandlerMappingName(pid,
151151
mapping_name,
@@ -694,4 +694,3 @@ bool Agent::IsWaitingForConnect() {
694694

695695
} // namespace inspector
696696
} // namespace node
697-

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ void SetupProcessObject(Environment* env,
34923492
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
34933493

34943494
READONLY_PROPERTY(process, "pid",
3495-
Integer::New(env->isolate(), GetProcessId()));
3495+
Integer::New(env->isolate(), uv_os_getpid()));
34963496
READONLY_PROPERTY(process, "features", GetFeatures(env));
34973497

34983498
process->SetAccessor(FIXED_ONE_BYTE_STRING(env->isolate(), "ppid"),

src/node_internals.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ void RegisterSignalHandler(int signal,
225225
bool reset_handler = false);
226226
#endif
227227

228-
uint32_t GetProcessId();
229228
bool SafeGetenv(const char* key, std::string* text);
230229

231230
std::string GetHumanReadableProcessName();

src/util.cc

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@
2222
#include "string_bytes.h"
2323
#include "node_buffer.h"
2424
#include "node_internals.h"
25+
#include "uv.h"
2526
#include <stdio.h>
2627

27-
#ifdef __POSIX__
28-
#include <unistd.h> // getpid()
29-
#endif
30-
31-
#ifdef _MSC_VER
32-
#include <windows.h> // GetCurrentProcessId()
33-
#endif
34-
3528
namespace node {
3629

3730
using v8::Isolate;
@@ -122,15 +115,7 @@ std::string GetHumanReadableProcessName() {
122115
void GetHumanReadableProcessName(char (*name)[1024]) {
123116
char title[1024] = "Node.js";
124117
uv_get_process_title(title, sizeof(title));
125-
snprintf(*name, sizeof(*name), "%s[%u]", title, GetProcessId());
126-
}
127-
128-
uint32_t GetProcessId() {
129-
#ifdef _WIN32
130-
return GetCurrentProcessId();
131-
#else
132-
return getpid();
133-
#endif
118+
snprintf(*name, sizeof(*name), "%s[%u]", title, uv_os_getpid());
134119
}
135120

136121
} // namespace node

0 commit comments

Comments
 (0)