diff options
| author | kennytm <kennytm@gmail.com> | 2017-11-21 03:14:43 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-21 03:14:43 +0800 |
| commit | fe2ec734bb4143182d009bca2776b26ddb8157ac (patch) | |
| tree | 03ce6bf7f9a494084d908474caa82179b4eeaf62 /src/libstd/sys | |
| parent | 3b1cf4d3c78185c3b00f952983a9066b42ca17aa (diff) | |
| parent | 1e42d5f2e1ab05f0f5d07f7c09644574c13e9a12 (diff) | |
| download | rust-fe2ec734bb4143182d009bca2776b26ddb8157ac.tar.gz rust-fe2ec734bb4143182d009bca2776b26ddb8157ac.zip | |
Rollup merge of #46092 - sfackler:ppid, r=alexcrichton
Add process::parent_id I have this as a Unix-only API since it seems like Windows doesn't have a similar API. r? @alexcrichton
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/redox/os.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/ext/process.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 4 |
3 files changed, 14 insertions, 0 deletions
diff --git a/src/libstd/sys/redox/os.rs b/src/libstd/sys/redox/os.rs index c27e2ee172c..480765b77a0 100644 --- a/src/libstd/sys/redox/os.rs +++ b/src/libstd/sys/redox/os.rs @@ -213,3 +213,7 @@ pub fn exit(code: i32) -> ! { pub fn getpid() -> u32 { syscall::getpid().unwrap() as u32 } + +pub fn getppid() -> u32 { + syscall::getppid().unwrap() as u32 +} diff --git a/src/libstd/sys/unix/ext/process.rs b/src/libstd/sys/unix/ext/process.rs index cde21b089a2..60309bec6d4 100644 --- a/src/libstd/sys/unix/ext/process.rs +++ b/src/libstd/sys/unix/ext/process.rs @@ -191,3 +191,9 @@ impl IntoRawFd for process::ChildStderr { self.into_inner().into_fd().into_raw() } } + +/// Returns the OS-assigned process identifier associated with this process's parent. +#[unstable(feature = "unix_ppid", issue = "46104")] +pub fn parent_id() -> u32 { + ::sys::os::getppid() +} diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 40b73f1b307..7e965b4b4c5 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -515,3 +515,7 @@ pub fn exit(code: i32) -> ! { pub fn getpid() -> u32 { unsafe { libc::getpid() as u32 } } + +pub fn getppid() -> u32 { + unsafe { libc::getppid() as u32 } +} |
