File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1167,6 +1167,24 @@ pub fn abort() -> ! {
11671167 unsafe { :: sys:: abort_internal ( ) } ;
11681168}
11691169
1170+ /// Returns the OS-assigned process identifier associated with this process.
1171+ ///
1172+ /// # Examples
1173+ ///
1174+ /// Basic usage:
1175+ ///
1176+ /// ```no_run
1177+ /// use std::process:current_pid;
1178+ ///
1179+ /// println!("My pid is {}", current_pid());
1180+ /// ```
1181+ ///
1182+ ///
1183+ #[ unstable( feature = "getpid" , issue = "44971" , reason = "recently added" ) ]
1184+ pub fn current_pid ( ) -> u32 {
1185+ :: sys:: os:: getpid ( )
1186+ }
1187+
11701188#[ cfg( all( test, not( target_os = "emscripten" ) ) ) ]
11711189mod tests {
11721190 use io:: prelude:: * ;
Original file line number Diff line number Diff line change @@ -209,3 +209,7 @@ pub fn exit(code: i32) -> ! {
209209 let _ = syscall:: exit ( code as usize ) ;
210210 unreachable ! ( ) ;
211211}
212+
213+ pub fn getpid ( ) -> u32 {
214+ syscall:: getpid ( ) . unwrap ( ) as u32
215+ }
Original file line number Diff line number Diff line change @@ -513,3 +513,7 @@ pub fn home_dir() -> Option<PathBuf> {
513513pub fn exit ( code : i32 ) -> ! {
514514 unsafe { libc:: exit ( code as c_int ) }
515515}
516+
517+ pub fn getpid ( ) -> u32 {
518+ unsafe { libc:: getpid ( ) as u32 }
519+ }
Original file line number Diff line number Diff line change @@ -318,6 +318,10 @@ pub fn exit(code: i32) -> ! {
318318 unsafe { c:: ExitProcess ( code as c:: UINT ) }
319319}
320320
321+ pub fn getpid ( ) -> u32 {
322+ unsafe { c:: GetCurrentProcessId ( ) as u32 }
323+ }
324+
321325#[ cfg( test) ]
322326mod tests {
323327 use io:: Error ;
You can’t perform that action at this time.
0 commit comments