Child process receives SIGHUP when it tries to write to the stdout. Try to write to log instead of printing to stdout.
On Nov 3, 12:27 pm, [email protected] wrote: > hi, > > In recent release of Android, I suddenly find the fork() will NOT run > sub-process once parent-process exit. For example, following program will > only output "main()", not output "sub-process continue": > ======================================== > printf("main()\n"); > > pid_t pid = fork(); > if(pid < 0) { > return -1; > }else if(pid > 0){ > exit(0); > } > > setsid(); > > printf("sub-process continue\n"); > ======================================== > > Maybe parent-process exit too fast, so, I add a sleep to delay > parent-process exit. So, test following program: > ======================================== > printf("main()\n"); > > pid_t pid = fork(); > if(pid < 0) { > return -1; > }else if(pid > 0){ > printf("parent-process exit\n"); > usleep(500); > exit(0); > } > > setsid(); > > printf("sub-process continue\n"); > ======================================== > > In most results, will output following: > ------------------------------------ > main() > parent-process exit > sub-process continue > ------------------------------------ > > However, sometimes still can't run sub-process, output following: > ------------------------------------ > main() > parent-process exit > ------------------------------------ > > Do you know what happen? > > Thanks. -- unsubscribe: [email protected] website: http://groups.google.com/group/android-kernel
