c - Reading in child process -


i'm having issue assignment.

i have read data terminal in child process, after parent process dies. written, parent process must die right after executing child process, solutions found ( such using wait() ) not usefull me.

my code

int main(void) {      printf("start main\n");     if(fork() == 0){         char buffer[64];         fgets(buffer, 64, stdin);         printf("child process: %s\n", buffer);     }     else printf("end main\n");     //using wait() here not allowed in assignment.     return 0; } 

it doesn't wait me enter data. seems after parent ends, child process in background , can not read data terminal.

the results

damian@damian-virtualbox:-$ ./testuje start main end main damian@damian-virtualbox:-$ child process:  echo test | ./testuje start main end damian@damian-virtualbox:-$ child process: test 

what program should do

print: start main print: end main should: wait user type print: child process: text_typed_by_user 

edit: suggested use tee command. have idea how use achive wanted?

you might want use vfork instead of fork (check documentation here):

pid_t vfork(void);  vfork - create child process , block parent 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -