You just need to use the dup2()duplicate file descriptor socket in the file descriptors stderr and stdout. This is almost the same as pipe redirection.
cpid = fork();
if (cpid == 0) {
dup2(sockfd, STDOUT_FILENO);
dup2(sockfd, STDERR_FILENO);
execvp(...);
source
share