File tree 4 files changed +31
-0
lines changed
4 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1310,6 +1310,25 @@ pub fn abort() -> ! {
1310
1310
unsafe { :: sys:: abort_internal ( ) } ;
1311
1311
}
1312
1312
1313
+ /// Returns the OS-assigned process identifier associated with this process.
1314
+ ///
1315
+ /// # Examples
1316
+ ///
1317
+ /// Basic usage:
1318
+ ///
1319
+ /// ```no_run
1320
+ /// #![feature(getpid)]
1321
+ /// use std::process;
1322
+ ///
1323
+ /// println!("My pid is {}", process::id());
1324
+ /// ```
1325
+ ///
1326
+ ///
1327
+ #[ unstable( feature = "getpid" , issue = "44971" , reason = "recently added" ) ]
1328
+ pub fn id ( ) -> u32 {
1329
+ :: sys:: os:: getpid ( )
1330
+ }
1331
+
1313
1332
#[ cfg( all( test, not( target_os = "emscripten" ) ) ) ]
1314
1333
mod tests {
1315
1334
use io:: prelude:: * ;
Original file line number Diff line number Diff line change @@ -209,3 +209,7 @@ pub fn exit(code: i32) -> ! {
209
209
let _ = syscall:: exit ( code as usize ) ;
210
210
unreachable ! ( ) ;
211
211
}
212
+
213
+ pub fn getpid ( ) -> u32 {
214
+ syscall:: getpid ( ) . unwrap ( ) as u32
215
+ }
Original file line number Diff line number Diff line change @@ -511,3 +511,7 @@ pub fn home_dir() -> Option<PathBuf> {
511
511
pub fn exit ( code : i32 ) -> ! {
512
512
unsafe { libc:: exit ( code as c_int ) }
513
513
}
514
+
515
+ pub fn getpid ( ) -> u32 {
516
+ unsafe { libc:: getpid ( ) as u32 }
517
+ }
Original file line number Diff line number Diff line change @@ -318,6 +318,10 @@ pub fn exit(code: i32) -> ! {
318
318
unsafe { c:: ExitProcess ( code as c:: UINT ) }
319
319
}
320
320
321
+ pub fn getpid ( ) -> u32 {
322
+ unsafe { c:: GetCurrentProcessId ( ) as u32 }
323
+ }
324
+
321
325
#[ cfg( test) ]
322
326
mod tests {
323
327
use io:: Error ;
You can’t perform that action at this time.
0 commit comments