My code is to copy any file from one folder to another. Below is my approach but i am not sure whether this is the best approach?There are two problem with my code :
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. Not able to find successful copied info ?
i tired by extraction status from waitpid in the parent process( 0 means success) but even if the usb(destination) is removed and try the operation it throw same 0 value i.e success how can i report for successful copied?
2. It takes 10-15 min to copy 1GB of data how can i increased it speed or time complexity?