Code: Select all
char *stdoutMsg = "This message will be sent to stdout\n";
write(STDOUT_FILENO,stdoutMsg,strlen(stdoutMsg));
// message sent to stdout
int sockid = socket(PF_UNIX,SOCK_STREAM,0);
dup2(sockid,STDOUT_FILENO);
close(sockid);
send(STDOUT_FILENO,stdoutMsg,strlen(stdoutMsg),0);
// message now sent to socket
geht
Code: Select all
int sockid = socket(PF_UNIX,SOCK_STREAM,0);
char *sockMsg = "This message will be sent to socket\n";
send(sockid,sockMsg,strlen(sockMsg),0);
// message sent to socket
dup2(STDOUT_FILENO,sockid);
close(STDOUT_FILENO);
write(sockid,sockMsg,strlen(sockMsg));
// message not sent to stdout
Mobile version