Skip to content

Commit 40acda2

Browse files
cjihrigMylesBorins
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 259f2d3 commit 40acda2

File tree

5 files changed

+6
-23
lines changed

5 files changed

+6
-23
lines changed

src/env.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void Environment::PrintSyncTrace() const {
177177
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
178178

179179
fprintf(stderr, "(node:%u) WARNING: Detected use of sync API\n",
180-
GetProcessId());
180+
uv_os_getpid());
181181

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

src/inspector_agent.cc

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

147-
pid = GetCurrentProcessId();
147+
pid = uv_os_getpid();
148148

149149
if (GetDebugSignalHandlerMappingName(pid,
150150
mapping_name,
@@ -692,4 +692,3 @@ bool Agent::IsWaitingForConnect() {
692692

693693
} // namespace inspector
694694
} // namespace node
695-

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -3465,7 +3465,7 @@ void SetupProcessObject(Environment* env,
34653465
process->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "env"), process_env);
34663466

34673467
READONLY_PROPERTY(process, "pid",
3468-
Integer::New(env->isolate(), GetProcessId()));
3468+
Integer::New(env->isolate(), uv_os_getpid()));
34693469
READONLY_PROPERTY(process, "features", GetFeatures(env));
34703470

34713471
CHECK(process->SetAccessor(env->context(),

src/node_internals.h

-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ void RegisterSignalHandler(int signal,
248248
bool reset_handler = false);
249249
#endif
250250

251-
uint32_t GetProcessId();
252251
bool SafeGetenv(const char* key, std::string* text);
253252

254253
std::string GetHumanReadableProcessName();

src/util.cc

+2-17
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)