summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2026-01-09 19:08:38 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2026-01-09 19:08:38 +0100
commit1df2706ab53db39f01a7e4dcbecdcdd083ee924c (patch)
tree8b15c235a4b7c0200da23853b9c197b9720b8482 /test
parenta0ccc413f3b5bcb0de429e4bfbedd9a1b32db24e (diff)
add a small test for gettid()HEADmaster
Diffstat (limited to 'test')
-rw-r--r--test/unistd/tst-gettid.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/unistd/tst-gettid.c b/test/unistd/tst-gettid.c
new file mode 100644
index 0000000..996ae15
--- /dev/null
+++ b/test/unistd/tst-gettid.c
@@ -0,0 +1,39 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <pthread.h>
+#include <stdlib.h>
+
+void *thread_func(void *arg)
+{
+ printf("Thread %ld:\n", (long)arg);
+ printf(" PID = %d\n", getpid());
+ printf(" TID = %d (gettid)\n", gettid());
+ printf(" pthread ID = %lu\n\n", pthread_self());
+ return NULL;
+}
+
+int main(void)
+{
+ const int NUM_THREADS = 3;
+ pthread_t threads[NUM_THREADS];
+
+ printf("Main thread:\n");
+ printf(" PID = %d\n", getpid());
+ printf(" TID = %d (gettid)\n", gettid());
+ printf(" pthread ID = %lu\n\n", pthread_self());
+
+ for (long i = 0; i < NUM_THREADS; i++) {
+ if (pthread_create(&threads[i], NULL, thread_func, (void *)i) != 0) {
+ perror("pthread_create");
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ for (int i = 0; i < NUM_THREADS; i++) {
+ pthread_join(threads[i], NULL);
+ }
+
+ return 0;
+}
+