LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 972|回复: 8

execl执行程序需要多久?

[复制链接]
发表于 2005-10-12 13:43:29 | 显示全部楼层 |阅读模式
我有一个图形界面的应用程序,运行时会有一个help button,点击button时,会执行下面的代码。开启如mozilla之类的browser,显示help信息。

但是在点击help button时,如果help browser应用没有处于打开状态,mozilla运行起来的速度很慢。特别是在这个应用程序运行起来后,第一次点击help button,需要等待较长的时间help的mozilla界面才能显示。

请问:这是什么原因?是什么造成了这个延迟?

execl (help_browser,
help_browser,
helppage_path, //若干htm文件路径(固定)
NULL);

//help_browser是系统自带的browser
/*
"/usr/bin/mozilla"
"/usr/X11R6/bin/mozilla"
"/usr/bin/nautilus"
*/

谢谢了!
 楼主| 发表于 2005-10-12 14:08:04 | 显示全部楼层
补充一下:
        if ((pid = fork ()) < 0) {
                perror ("fork");
                exit (1);
        } else if (pid == 0) { /* child process */
                int fd = open ("/dev/null", O_WRONLY);
                if (fd < 0) {
                        perror ("open /dev/null");
                } else {
                        if (dup2 (fd, 1) < 0 || dup2 (fd, 2)) {
                                perror ("dup2");
                        }
                }
                execl (help_browser,
                        help_browser,
                        helppage_path,
                        NULL);
        }
这段程序应该是这样的,现fork一个进程,在执行execl。

程序在运行时,如果是第一次点击help button,需要等待的时间很难计算,有时候很久都不能打开help browser,需要点击2、3次才能打开。

请问这个等待是什么原因?

万分感谢!
回复 支持 反对

使用道具 举报

发表于 2005-10-12 17:04:15 | 显示全部楼层
1.MOZILLA正常打开的时间是之少?
2. execl 之后加入一行执行出错时的调试信息.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-13 11:08:17 | 显示全部楼层
1, I just count the mozilla opening time, it takes about 4~5 seconds to open a page.
2, I add some printf command to see the time used, it seems like:

begin to fork() Thu Oct 13 10:43:16 2005
Thu Oct 13 10:43:16 2005 return 0 //can not open, seems like no response
begin to fork() Thu Oct 13 10:44:12 2005
Thu Oct 13 10:44:12 2005 return 0 //can not open, seems like no response
begin to fork() Thu Oct 13 10:44:42 2005
Thu Oct 13 10:44:42 2005 return 0 //opened

The code is:

int exRet = 0;
cur_time = time(NULL);
strncpy (buffer, ctime(&cur_time),24);
printf("begin to fork() %s \n", buffer);//current time

if ((pid = fork ()) < 0) {
perror ("fork");
exit (1);
} else if (pid == 0) { /* child process */
int fd = open ("/dev/null", O_WRONLY);
if (fd < 0) {
perror ("open /dev/null");
} else {
if (dup2 (fd, 1) < 0 || dup2 (fd, 2)) {
perror ("dup2");
}
}

exRet = //return value of execl
execl (help_browser,
help_browser,
helppage_path,
NULL);
}

cur_time = time(NULL);
strncpy (buffer, ctime(&cur_time),24);
printf(" %s return %d \n", buffer, exRet);

另外,很少的机会,mozilla打开的时间并不长,但是多数情况下,第一次运行时,需要较长的时间,而且有时没有相应,只能重新点击。
回复 支持 反对

使用道具 举报

发表于 2005-10-13 14:57:38 | 显示全部楼层
如果是这样,不如先把mozilla预先启动好,隐藏起来,要显示帮助是用remote打开
回复 支持 反对

使用道具 举报

发表于 2005-10-13 16:53:23 | 显示全部楼层
我觉得这不大关事儿啊. 那是MOZILLA的问题.
你试试用DILLO打开你的帮助. 特快.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-13 17:05:10 | 显示全部楼层
能具体说一下
怎么隐藏已经启动好的进程和remode打开吗?

我查了一个linux隐藏进程的内容,可是不很明白,能够帮忙指点一下吗?我对linux不熟。
谢谢了!

具体如下:

在Linux中不存在直接查询进程信息的系统调用,类似于ps这样查询进程信息的命令是通过查询proc文件系统来实现的,在背景知识中已经介绍过proc文件系统,由于它应用文件系统的接口实现,因此同样可以用隐藏文件的方法来隐藏proc文件系统中的文件,只需要在上面的hacked_getdents中加入对于proc文件系统的判断即可。由于proc是特殊的文件系统,只存在于内存之中,不存在于任何实际设备之上,所以Linux内核分配给它一个特定的主设备号0以及一个特定的次设备号1,除此之外,由于在外存上没有与之对应的i节点,所以系统也分配给它一个特殊的节点号PROC_ROOT_INO(值为1),而设备上的1号索引节点是保留不用的。通过上面的分析,可以得出判断一个文件是否属于proc文件系统的方法:

  1)得到该文件对应的inode结构dinode;
  2)if (dinode->i_ino == PROC_ROOT_INO && !MAJOR(dinode->i_dev) && MINOR(dinode->i _dev) == 1) {该文件属于proc文件系统}

  通过上面的分析,给出隐藏特定进程的伪代码表示:

  hacket_getdents(unsigned int fd, struct dirent *dirp, unsigned int count)
  {

调用原来的系统调用;

  得到fd所对应的节点;

  if(该文件属于proc文件系统&&该文件名需要隐藏)
    {从dirp中去掉该文件相关信息}
}


谢谢了!
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-13 17:28:21 | 显示全部楼层
是这样的,我的程序是要在一些指定的系统下运行的

目前的browser有这样一些:
#define BROWSER_1 "/usr/bin/mozilla"  // the most popular web browser in linux
#define BROWSER_2 "/usr/X11R6/bin/mozilla"  // mazilla's path in SuSE Linux
#define BROWSER_3 "/usr/bin/nautilus" // gnome default help file browser
#define BROWSER_4 "/usr/bin/netscape" // another old web browser in linux

我目前是在Mandrake下面,不过近期需要运行在Fedora下面。
我查了一下,dillo好像不是很通用。

另外,至于这个速度,它的确不太影响使用,多点击几次总会打开help文档。但是,它总是不太好用,在测试的时候,因为相应慢或者需要多点击几次,被报成了bug。
这个速度对于使用来说,总是不太理想,所以希望能改得好一些。

Post by 弥敦路九号
我觉得这不大关事儿啊. 那是MOZILLA的问题.
你试试用DILLO打开你的帮助. 特快.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2005-10-13 19:46:23 | 显示全部楼层
继续请教:

刚刚跟踪了一下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         }
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表