|
楼主 |
发表于 2005-10-13 19:59:55
|
显示全部楼层
继续请教:
刚刚跟踪了一下fork以后的pid,发现点击help button 后没有打开mozilla的情况,虽然fork成功,也获得了子进程的pid,但是/proc/下面并没有相应进程的目录及其相应的文件。当能打开mozilla时,相应的文件在/proc/就生成了。
请问这是什么原因?fork之后,子进程怎么了?
begin to fork() Thu Oct 13 19:37:23 2005
in child
child_pid 29551// 没有打开mozilla,也不存在/proc/29551
in parent
Thu Oct 13 19:37:24 2005 return 0
begin to fork() Thu Oct 13 19:38:23 2005
in child
child_pid 29597// 没有打开mozilla,也不存在/proc/29597
in parent
Thu Oct 13 19:38:24 2005 return 0
begin to fork() Thu Oct 13 19:39:00 2005
in child
child_pid 29627// 没有打开mozilla,也不存在/proc/29627
in parent
Thu Oct 13 19:39:01 2005 return 0
begin to fork() Thu Oct 13 19:39:30 2005
in child
child_pid 29654// 没有打开mozilla,也不存在/proc/29654
in parent
Thu Oct 13 19:39:31 2005 return 0
begin to fork() Thu Oct 13 19:39:56 2005
in child
child_pid 29678// 打开了mozilla,存在/proc/29678
in parent
代码如下:
{
1786 //DEBUG by Annie
1787 //
1788 char buffer[24];
1789 int exRet = 0;
1790 int status;
1791 time_t cur_time = time(NULL);
1792 strncpy (buffer, ctime(&cur_time),24);
1793 printf("begin to fork() %s \n", buffer);
1794
1795 pid = fork();
1796 if (pid < 0) {
1797 //if ((pid = fork ()) < 0) {
1798 perror ("fork");
1799 exit (1);
1800 } else if (pid == 0) { /* child process */
1801 puts("in child");
1802 printf("child_pid %d \n", getpid());
1803 int fd = open ("/dev/null", O_WRONLY);
1804 if (fd < 0) {
1805 perror ("open /dev/null");
1806
1807
1808 } else {
1809 if (dup2 (fd, 1) < 0 || dup2 (fd, 2)) {
1810 perror ("dup2");
1811
1812
1813 }
1814 //adjusted by Annie
1815 exRet =
1816 execl (help_browser,
1817 help_browser,
1818 helppage_path,
1819 NULL);
1820 }
1821 /*exRet =
1822 execl (help_browser,
1823 help_browser,
1824 helppage_path,
1825 NULL);*/
1826 //========================
1827 }
1828 //added by Annie
1829 else { /* parent process */
1830 puts("in parent");
1831
1832 }
1833 //========================
1834 //}
1835
1836 cur_time = time(NULL);
1837 strncpy (buffer, ctime(&cur_time),24);
1838 printf("%s return %d \n", buffer, exRet);
1839
1840 /* because set the handler of SIGCHLD to SIG_IGN,
1841 * here need not wait the exit of child process.
1842 * The child process will not become a zombie.
1843 */
1844
1845
1846 return;
1847
1848 } |
|