Last active
February 20, 2020 01:53
-
-
Save khalefa-phd/4b93c6d339b7a1708f9c62ddd5b70b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
int main() { | |
pid_t ChildID; | |
ChildID = fork(); // check for Fork | |
if (ChildID >= 0) // fork sucess | |
{ | |
if (ChildID == 0) // Code Of Child which the value will be 0 in | |
// case of Child code | |
{ | |
char* argv[4]; | |
argv[0] = "ls"; | |
argv[1] = NULL; | |
execv(argv[0], argv); | |
} else // Code of parent and the value of ChildID = process ID of child in | |
// case of | |
{ | |
wait(NULL); | |
} | |
} else { | |
printf("Fork is fail \n"); | |
return 1; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment