Skip to content

Instantly share code, notes, and snippets.

@khalefa-phd
Last active February 20, 2020 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khalefa-phd/4b93c6d339b7a1708f9c62ddd5b70b3e to your computer and use it in GitHub Desktop.
Save khalefa-phd/4b93c6d339b7a1708f9c62ddd5b70b3e to your computer and use it in GitHub Desktop.
#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