Skip to content

Commit 8a2f0db

Browse files
committed
Add gettid
1 parent 3f0c3e1 commit 8a2f0db

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/unistd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> {
5656
Errno::result(res).map(drop)
5757
}
5858

59+
#[cfg(target_os = "linux")]
60+
#[inline]
61+
pub fn gettid() -> pid_t {
62+
unsafe { libc::syscall(libc::SYS_gettid) as i32 } // no error handling, according to man page: "These functions are always successful."
63+
}
64+
5965
#[inline]
6066
pub fn dup(oldfd: RawFd) -> Result<RawFd> {
6167
let res = unsafe { libc::dup(oldfd) };

test/test_unistd.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ fn test_getpid() {
5454
assert!(ppid > 0);
5555
}
5656

57+
#[cfg(target_os = "linux")]
58+
#[test]
59+
fn test_gettid() {
60+
let tid = gettid();
61+
assert!(tid > 0);
62+
}
63+
5764
macro_rules! execve_test_factory(
5865
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
5966
#[test]

0 commit comments

Comments
 (0)