Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/std/src/os/unix/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,5 +593,5 @@ impl From<OwnedFd> for process::ChildStderr {
#[must_use]
#[stable(feature = "unix_ppid", since = "1.27.0")]
pub fn parent_id() -> u32 {
crate::sys::os::getppid()
crate::sys::process::getppid()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can implement getppid on windows, don't know why we do not have it.

}
2 changes: 1 addition & 1 deletion library/std/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2545,7 +2545,7 @@ pub fn abort() -> ! {
#[must_use]
#[stable(feature = "getpid", since = "1.26.0")]
pub fn id() -> u32 {
crate::sys::os::getpid()
imp::getpid()
}

/// A trait for implementing arbitrary return types in the `main` function.
Expand Down
5 changes: 0 additions & 5 deletions library/std/src/sys/pal/hermit/os.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use super::hermit_abi;
use crate::ffi::{OsStr, OsString};
use crate::marker::PhantomData;
use crate::path::{self, PathBuf};
Expand Down Expand Up @@ -56,7 +55,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
unsafe { hermit_abi::getpid() as u32 }
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/motor/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("Pids on Motor OS are u64.")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/sgx/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids in SGX")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/solid/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/teeos/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/uefi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
8 changes: 0 additions & 8 deletions library/std/src/sys/pal/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,14 +533,6 @@ pub fn home_dir() -> Option<PathBuf> {
}
}

pub fn getpid() -> u32 {
unsafe { libc::getpid() as u32 }
}

pub fn getppid() -> u32 {
unsafe { libc::getppid() as u32 }
}

#[cfg(all(target_os = "linux", target_env = "gnu"))]
pub fn glibc_version() -> Option<(usize, usize)> {
unsafe extern "C" {
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/unsupported/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/wasi/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@ pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("unsupported");
}

#[doc(hidden)]
pub trait IsMinusOne {
fn is_minus_one(&self) -> bool;
Expand Down
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/windows/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,3 @@ pub fn home_dir() -> Option<PathBuf> {
.map(PathBuf::from)
.or_else(home_dir_crt)
}

pub fn getpid() -> u32 {
unsafe { c::GetCurrentProcessId() }
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/xous/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 0 additions & 4 deletions library/std/src/sys/pal/zkvm/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,3 @@ pub fn temp_dir() -> PathBuf {
pub fn home_dir() -> Option<PathBuf> {
None
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 3 additions & 1 deletion library/std/src/sys/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ cfg_select! {
mod env;

pub use env::CommandEnvs;
#[cfg(target_family = "unix")]
pub use imp::getppid;
pub use imp::{
ChildPipe, Command, CommandArgs, EnvKey, ExitCode, ExitStatus, ExitStatusError, Process, Stdio,
read_output,
getpid, read_output,
};

#[cfg(any(
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/sys/process/motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,7 @@ pub fn read_output(
) -> io::Result<()> {
Err(io::Error::from_raw_os_error(moto_rt::E_NOT_IMPLEMENTED.into()))
}

pub fn getpid() -> u32 {
panic!("Pids on Motor OS are u64.")
}
4 changes: 4 additions & 0 deletions library/std/src/sys/process/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,7 @@ fn env_changes(env: &CommandEnv) -> Option<BTreeMap<EnvKey, (Option<OsString>, O

Some(result)
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
8 changes: 8 additions & 0 deletions library/std/src/sys/process/unix/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,11 @@ pub fn read_output(
}
}
}

pub fn getpid() -> u32 {
unsafe { libc::getpid() as u32 }
}

pub fn getppid() -> u32 {
unsafe { libc::getppid() as u32 }
}
4 changes: 3 additions & 1 deletion library/std/src/sys/process/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ cfg_select! {

pub use imp::{ExitStatus, ExitStatusError, Process};

pub use self::common::{ChildPipe, Command, CommandArgs, ExitCode, Stdio, read_output};
pub use self::common::{
ChildPipe, Command, CommandArgs, ExitCode, Stdio, getpid, getppid, read_output,
};
pub use crate::ffi::OsString as EnvKey;
4 changes: 4 additions & 0 deletions library/std/src/sys/process/unsupported.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,7 @@ pub fn read_output(
) -> io::Result<()> {
match out.diverge() {}
}

pub fn getpid() -> u32 {
panic!("no pids on this platform")
}
4 changes: 4 additions & 0 deletions library/std/src/sys/process/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,3 +976,7 @@ impl<'a> fmt::Debug for CommandArgs<'a> {
f.debug_list().entries(self.iter.clone()).finish()
}
}

pub fn getpid() -> u32 {
unsafe { c::GetCurrentProcessId() }
}
Loading