File tree 4 files changed +30
-0
lines changed
4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -1167,6 +1167,24 @@ pub fn abort() -> ! {
1167
1167
unsafe { :: sys:: abort_internal ( ) } ;
1168
1168
}
1169
1169
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
+
1170
1188
#[ cfg( all( test, not( target_os = "emscripten" ) ) ) ]
1171
1189
mod tests {
1172
1190
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 @@ -513,3 +513,7 @@ pub fn home_dir() -> Option<PathBuf> {
513
513
pub fn exit ( code : i32 ) -> ! {
514
514
unsafe { libc:: exit ( code as c_int ) }
515
515
}
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) -> ! {
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