Skip to content

Instantly share code, notes, and snippets.

@iamsuneeth
Created July 24, 2012 15:41
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 iamsuneeth/3170754 to your computer and use it in GitHub Desktop.
Save iamsuneeth/3170754 to your computer and use it in GitHub Desktop.
#include<stdio.h>
#include<sys/types.h>
#include<unistd.h>
#include<stdlib.h>
main()
{
int pid;
pid=fork();
char *a = (char *)malloc(sizeof(a));
char *b = (char *)malloc(sizeof(b));
if(pid==-1)
{printf("Error");
exit(1);
}
if(pid==0)
{ printf("\nIn child process: %d",getpid());
sleep(3);
printf("\nparent id: %d",getppid());
sleep(5);
printf("\nDisplay the contents of any directory: ");
printf("\nEnter directory: ");
scanf("%s",a);
execl("/bin/ls","ls",a,NULL);
}
else
{ wait();
printf("\nIn parent process: %d",getpid());
sleep(5);
printf("\nDisplay man page of linux commands: ");
printf("\nEnter command: ");
scanf("%s",b);
execl("/usr/bin/man","man",b,NULL);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment