fork download
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <unistd.h> //Header file for sleep(). man 3 sleep for details.
  5. #include <pthread.h>
  6.  
  7. // A normal C function that is executed as a thread
  8. // when its name is specified in pthread_create()
  9. void *myThreadFun(void *vargp)
  10. {
  11. sleep(1);
  12. printf("Printing GeeksQuiz from Thread %d \t \n",pthread_self());
  13. //pthread_exit();
  14. return NULL;
  15. }
  16.  
  17. int main()
  18. {
  19. pthread_t thread_id;
  20. printf("Before Thread\n");
  21. for(int i = 0;i<2;i++){
  22.  
  23. pthread_create(&thread_id, NULL, myThreadFun, NULL);
  24. // printf("process id is %d\n",pthread_self());
  25. }
  26.  
  27.  
  28. pthread_join(thread_id, NULL);
  29.  
  30. printf("After Thread\n");
  31. return 0;
  32. }
Success #stdin #stdout 0s 5548KB
stdin
Standard input is empty
stdout
Before Thread
Printing GeeksQuiz from Thread  1011635968 	 
After Thread