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.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en