Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/types.h>
- int main() {
- // fork creates a child process.
- pid_t child = fork();
- if(child < 0) {
- printf("Error forking!\n");
- return 0;
- }
- // if the value of child pid is equal to 0 then we're in the child process
- else if(child == 0) {
- printf("Hello from the child (PID=%d)\n", getpid());
- exit(0);
- }
- // Waits until the child finishes.
- wait(NULL);
- printf("Parent(PID=%d) exiting...\n", getpid());
- return 0;
- }
Add Comment
Please, Sign In to add comment