#include<stdio.h> #include<unistd.h> #include<sys/types.h> #include<sys/wait.h> #include<stdlib.h> int main() { int pid; pid=fork(); if(pid<0) { printf("\nfork failed\n"); exit(-1); } else if(pid==0) { printf("welcome to parent"); execlp("/bin/ls","ls","-1",NULL); } else { wait(NULL); printf("\nchild complete\n"); exit(0); }}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter