首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

fork()函数的有关问题,在虚拟机上好用,手机上不好用

2012-03-01 
fork()函数的问题,在虚拟机上好用,手机上不好用!在虚拟机上,程序执行成功,WEXITSTATUS(status)返回0;在手

fork()函数的问题,在虚拟机上好用,手机上不好用!
在虚拟机上,程序执行成功,WEXITSTATUS(status)返回0;在手机上(Linux环境)WEXITSTATUS(status)返回1,cp操作失败。谁知道为什么?一样的代码。

BOOL   CopyFile(CHAR*   sourcePath,   CHAR*   destPath)
{
char   prog[20]   =   "/bin/cp ";
char   *arg[10];
int   i   =   0;
int   pid;
int   res;

MTP_DBG( "prepare   to   move   file   from   %s   to   %s\n. ",sourcePath,   destPath);

if   (   NULL   ==   sourcePath   )
return   FALSE;
if   (   NULL   ==   destPath   )
return   FALSE;

pid   =   fork();

if   (pid   ==   0)
{   /*   child   */
arg[i++]   =   prog;
arg[i++]   =   "-f ";
arg[i++]   =   sourcePath;
arg[i++]   =   destPath;

execv(prog,arg);
exit(1);   /*   exec   failed   */
}
else   if   (pid   !=   -1)
{
                /*   parent   */
int   status;

                //         wait(&status);
MTP_DBG( "Parent   process:   before   waiting   child.\n ")   ;
waitpid(pid,&status,0);
res   =   (WIFEXITED(status)?   WEXITSTATUS(status):-1);

MTP_DBG( "Parent   process:   after   waiting   child,   res   =   %d\n ",   res)   ;

                  return   TRUE;
                /*   strerror(errno)   can   get   the   cause   */
}

        return   FALSE;

}

[解决办法]
UP

热点排行