Guest User

Untitled

a guest
May 22nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <sys/types.h>
  4. #include <sys/syscall.h>
  5. #include <pthread.h>
  6. #include <unistd.h>
  7.  
  8. void * thread(void *arg)
  9. {
  10.     sleep(1);
  11.     printf("T self: %lu\n", pthread_self());
  12.     printf("T tid: %lu\n", syscall(SYS_gettid));
  13.     printf("T pid: %u\n", getpid());
  14.     sleep(2);
  15.     return 0;
  16. }
  17.  
  18. int main()
  19. {
  20.     pthread_t tid;
  21.  
  22.     pthread_create(&tid, NULL, thread, NULL);
  23.  
  24.     printf("Started thread: %lu\n", tid);
  25.  
  26.     printf("M self: %lu\n", pthread_self());
  27.     printf("M tid: %lu\n", syscall(SYS_gettid));
  28.     printf("M pid: %u\n", getpid());
  29.  
  30.     pthread_join(tid, NULL);
  31.  
  32.     return 0;
  33. }
Add Comment
Please, Sign In to add comment