Why is my parent process not waiting the second time? C/Unix -



Why is my parent process not waiting the second time? C/Unix -

so, trying create kid process, have execute execl , run ls. after ls done, create kid process , have run cat command on file. sec wait(pid) not seem wait sec kid process finish before finishing. here code , output

#include <fcntl.h> int main(){ int pid; printf("in parent process, creating kid now...\n"); pid = fork(); if (pid==0){ printf("now in kid process...\n"); execl("/bin/ls","ls","-l",(char*)0); } wait(pid); printf("ls kid process complete\n"); printf("in parent process\n"); printf("creating kid process\n"); pid=fork(); if(pid==0){ execl("/bin/cat","cat","f1",(char*)0); } wait(pid); homecoming 0; }

here output

in parent process, creating kid now... in kid process... "contents of ls" ls kid process finish in parent process creating kid process [username@host ~]$ "contents of file" *cursor*

the parent process seems finish before sec kid complete. there 1 kid existing @ time. "contents of file" supposed appear before [username@host ~]$ prompt. think misplacing wait or wrong pid assignment or something. in advance!

the argument wait() not pid. it's pointer int exit status stored. you're passing integer pointer needed, means:

the programme might crash or corrupt unrelated memory location phone call wait. behavior after point unpredictable. you need enable more compiler warnings , pay attending them.

c unix

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -