Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <pthread.h>
- #include <unistd.h>
- #include <sys/wait.h>
- void* say_hello(void* data) {
- char *str;
- str = (char*)data;
- printf("%s\n", str);
- // return;
- }
- void main(int argc, char **argv) {
- pthread_t tp1, tp2, tc1, tc2;
- pid_t child_pid = 0;
- printf("HELLO WORLD!\n\n");
- child_pid = fork();
- if (child_pid == 0) {
- pthread_create(&tc1, NULL, say_hello, "First thread from child process");
- pthread_create(&tc2, NULL, say_hello, "Second thread from child process");
- pthread_join(tc1, NULL);
- pthread_join(tc2, NULL);
- } else {
- pthread_create(&tp1, NULL, say_hello, "First thread from parent process");
- pthread_create(&tp1, NULL, say_hello, "Second thread from parent process");
- pthread_join(tp1, NULL);
- pthread_join(tp2, NULL);
- wait(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement