unix,win: add uv_os_getppid()

Refs: https://github.com/nodejs/node/issues/14957
PR-URL: https://github.com/libuv/libuv/pull/1610
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
cjihrig 2017-10-30 19:21:34 -04:00
parent 719dfecf95
commit e8e6a8a500
No known key found for this signature in database
GPG Key ID: 7434390BDBE9B9C5
9 changed files with 27 additions and 3 deletions

View File

@ -59,6 +59,12 @@ Data types
Abstract representation of a file descriptor. On Unix systems this is a
`typedef` of `int` and on Windows a `HANDLE`.
.. c:type:: uv_pid_t
Cross platform representation of a `pid_t`.
.. versionadded:: 1.16.0
.. c:type:: uv_rusage_t
Data type for resource usage results.
@ -221,6 +227,12 @@ API
On Windows not all fields are set, the unsupported fields are filled with zeroes.
See :c:type:`uv_rusage_t` for more details.
.. c:function:: uv_pid_t uv_os_getppid(void)
Returns the parent process ID.
.. versionadded:: 1.16.0
.. c:function:: int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count)
Gets information about the CPUs on the system. The `cpu_infos` array will

View File

@ -123,6 +123,7 @@ typedef struct uv_buf_t {
typedef int uv_file;
typedef int uv_os_sock_t;
typedef int uv_os_fd_t;
typedef pid_t uv_pid_t;
#define UV_ONCE_INIT PTHREAD_ONCE_INIT

View File

@ -222,6 +222,7 @@ typedef struct uv_buf_t {
typedef int uv_file;
typedef SOCKET uv_os_sock_t;
typedef HANDLE uv_os_fd_t;
typedef int uv_pid_t;
typedef HANDLE uv_thread_t;

View File

@ -1069,6 +1069,7 @@ UV_EXTERN int uv_os_homedir(char* buffer, size_t* size);
UV_EXTERN int uv_os_tmpdir(char* buffer, size_t* size);
UV_EXTERN int uv_os_get_passwd(uv_passwd_t* pwd);
UV_EXTERN void uv_os_free_passwd(uv_passwd_t* pwd);
UV_EXTERN uv_pid_t uv_os_getppid(void);
UV_EXTERN int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count);
UV_EXTERN void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count);

View File

@ -1343,3 +1343,8 @@ int uv_os_gethostname(char* buffer, size_t* size) {
uv_os_fd_t uv_get_osfhandle(int fd) {
return fd;
}
uv_pid_t uv_os_getppid(void) {
return getppid();
}

View File

@ -326,7 +326,6 @@ void uv__fs_poll_endgame(uv_loop_t* loop, uv_fs_poll_t* handle);
void uv__util_init(void);
uint64_t uv__hrtime(double scale);
int uv_parent_pid(void);
int uv_current_pid(void);
__declspec(noreturn) void uv_fatal_error(const int errorno, const char* syscall);
int uv__getpwuid_r(uv_passwd_t* pwd);

View File

@ -1969,7 +1969,7 @@ int uv_pipe_open(uv_pipe_t* pipe, uv_file file) {
if (pipe->ipc) {
assert(!(pipe->flags & UV_HANDLE_NON_OVERLAPPED_PIPE));
pipe->pipe.conn.ipc_pid = uv_parent_pid();
pipe->pipe.conn.ipc_pid = uv_os_getppid();
assert(pipe->pipe.conn.ipc_pid != -1);
}
return 0;

View File

@ -331,7 +331,7 @@ uint64_t uv_get_total_memory(void) {
}
int uv_parent_pid(void) {
uv_pid_t uv_os_getppid(void) {
int parent_pid = -1;
HANDLE handle;
PROCESSENTRY32 pe;

View File

@ -29,6 +29,7 @@ TEST_IMPL(platform_output) {
size_t rss;
size_t size;
double uptime;
uv_pid_t ppid;
uv_rusage_t rusage;
uv_cpu_info_t* cpus;
uv_interface_address_t* interfaces;
@ -144,5 +145,9 @@ TEST_IMPL(platform_output) {
printf(" shell: %s\n", pwd.shell);
printf(" home directory: %s\n", pwd.homedir);
ppid = uv_os_getppid();
ASSERT(ppid > 0);
printf("uv_os_getppid: %d\n", (int) ppid);
return 0;
}