1 /* Smoke test for the gettid system call.
2 Copyright (C) 2019-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <support/check.h>
20 #include <support/namespace.h>
21 #include <support/xthread.h>
22 #include <support/xunistd.h>
24 /* TID of the initial (main) thread. */
25 static pid_t initial_tid
;
27 /* Check that PID and TID are the same in a subprocess. */
29 subprocess (void *closure
)
31 TEST_COMPARE (getpid (), gettid ());
32 TEST_VERIFY (gettid () != initial_tid
);
35 /* Check that the TID changes in a new thread. */
37 threadfunc (void *closure
)
39 TEST_VERIFY (getpid () != gettid ());
40 TEST_VERIFY (gettid () != initial_tid
);
44 /* Check for interactions with vfork. */
48 pid_t proc
= vfork ();
51 if (getpid () != gettid ())
53 if (gettid () == initial_tid
)
58 xwaitpid (proc
, &status
, 0);
59 TEST_COMPARE (status
, 0);
65 initial_tid
= gettid ();
67 /* The main thread has the same TID as the PID. */
68 TEST_COMPARE (getpid (), gettid ());
72 support_isolate_in_subprocess (subprocess
, NULL
);
74 xpthread_join (xpthread_create (NULL
, threadfunc
, NULL
));
79 #include <support/test-driver.c>