Advertisement
leadsan

Untitled

Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<pthread.h>
  3.  
  4. void* say_hello(void* data)
  5. {
  6.     char *str;
  7.     str = (char*)data;
  8.     printf("%s\n",str);
  9. }
  10.  
  11.  
  12. void main()
  13. {  
  14.     pthread_t t1, t2, t3, t4;
  15.    
  16.     int childpid;
  17.    
  18.     childpid = fork();
  19.     if (childpid == 0) {
  20.         pthread_create(&t1,NULL,say_hello, "First thread from parent process");
  21.         pthread_create(&t2,NULL,say_hello, "Second thread from parent process");
  22.     }
  23.     else {
  24.         pthread_create(&t3,NULL,say_hello,"First thread from child process");
  25.         pthread_create(&t4,NULL,say_hello,"Second thread from child process");
  26.     }
  27.     waitpid(childpid, NULL, 0);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement