1

我的代码是将任何文件从一个文件夹复制到另一个文件夹。以下是我的方法,但我不确定这是否是最好的方法?我的代码有两个问题:

int copycommand(char *source, char *destination)
{
        int childExitStatus;
        pid_t pid;
        int status;
        pid = fork();

        if (pid == 0) { /* child */
                execl("/bin/cp", "/bin/cp", "-R", source, destination, (char *)0);
        }

        }
        else {

                pid_t ws = waitpid( pid, &childExitStatus, WNOHANG);
                if (ws == -1)
                { /* error - handle as you wish */
                }
                if( WIFEXITED(childExitStatus)) /* exit code in childExitStatus */
                {
                        status = WEXITSTATUS(childExitStatus); /* zero is normal exit */
                        /* handle non-zero as you wish */
                   printf("%d\n",status);
                }
                else if (WIFSIGNALED(childExitStatus)) /* killed */
                {
                }
                else if (WIFSTOPPED(childExitStatus)) /* stopped */
                {
                }
        }
}

1. 找不到成功复制的信息?

我厌倦了父进程中waitpid的提取状态(0表示成功)但即使USB(目标)被移除并尝试操作它抛出相同的0值即成功我如何报告成功复制?

2. 复制 1GB 数据需要 10-15 分钟,如何提高速度或时间复杂度?

4

0 回答 0