Skip to content

Commit fe2ec73

Browse files
authored
Rollup merge of rust-lang#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
2 parents 3b1cf4d + 1e42d5f commit fe2ec73

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/libstd/sys/redox/os.rs

+4
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,7 @@ pub fn exit(code: i32) -> ! {
213213
pub fn getpid() -> u32 {
214214
syscall::getpid().unwrap() as u32
215215
}
216+
217+
pub fn getppid() -> u32 {
218+
syscall::getppid().unwrap() as u32
219+
}

src/libstd/sys/unix/ext/process.rs

+6
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,9 @@ impl IntoRawFd for process::ChildStderr {
191191
self.into_inner().into_fd().into_raw()
192192
}
193193
}
194+
195+
/// Returns the OS-assigned process identifier associated with this process's parent.
196+
#[unstable(feature = "unix_ppid", issue = "46104")]
197+
pub fn parent_id() -> u32 {
198+
::sys::os::getppid()
199+
}

src/libstd/sys/unix/os.rs

+4
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,7 @@ pub fn exit(code: i32) -> ! {
515515
pub fn getpid() -> u32 {
516516
unsafe { libc::getpid() as u32 }
517517
}
518+
519+
pub fn getppid() -> u32 {
520+
unsafe { libc::getppid() as u32 }
521+
}

0 commit comments

Comments
 (0)