#include #include #include #include #include #include int var_glb; /* A global variable*/ int main(void) { pid_t childPID; int var_lcl = 0; printf("\n################# parent: start ###################################\n"); setvbuf (stdout, NULL, _IONBF, BUFSIZ); childPID = fork(); if(childPID >= 0) // fork was successful { if(childPID == 0) // child process { printf("\n----------------- child: start ----------------------------------\n"); var_lcl++; var_glb++; printf("\n Child Process (before calling system) :: ls -al /etc/mc\n"); system("/usr/bin/ls -a -l /etc/mc/"); printf("\n Child Process (after calling system) :: var_lcl = [%d], var_glb[%d]\n", var_lcl, var_glb); printf("\n----------------- child: stop ------------------------------------\n"); } else //Parent process { var_lcl = 10; var_glb = 20; printf("\n Parent process :: var_lcl = [%d], var_glb[%d]\n", var_lcl, var_glb); } } else // fork failed { printf("\n Fork failed, quitting!!!!!!\n"); return 1; } printf("\n################# parent: stop ####################################\n"); return 0; }