Okay, so all you really need is some fork logic, no execlp. Here is some pseudo code:
Code:
function main
int pfd[2]; // to be used with pipe() function
initialization and error checking
if (pipe(pfd) == -1)
exit with error
// you may want a second call to pipe if you need 2-way communication
switch on fork()
case -1:
handle error and quit
case 0:
close(pfd[1]);
do_child_stuff(argv[2], pfd[0])
close(pfd[0]);
break
default:
close(pfd[0]);
do_parent_stuff(argv[1], pfd[1])
close(pfd[1]);
break;
return 0
function do_parent_stuff(char *src_path, int pfd)
opendir(src_path)
for each entry from readdir
write(pfd, entry->d_name, strlen(entry->d_name)
// maybe wait for child to report success here
closedir
function do_child_stuff(char *src_path, char *dst_path, int pfd)
while read(pfd, buf, sizeof(buf))
copy_file(src_path, dst_path, buf)
// maybe send success back to parent here
function copy_file(char *src, char *dest, char *file_name)
this function can use system or do it's own set of read/write or
fread/fwrite calls to copy the contents from src to dest