C/C++の宿題片付けます 166代目
■ このスレッドは過去ログ倉庫に格納されています
0548デフォルトの名無しさん
2013/12/18(水) 00:16:42.38#include <stdio.h>
#include <unistd.h>
int main(void) {
int ret, pipefd[2];
pid_t cpid;
if (pipe(pipefd) < 0)
return 1;
cpid = fork();
if (cpid < 0)
return close(pipefd[0]), close(pipefd[1]), 1;
if (cpid == 0) {
close(pipefd[0]);
ret = write(pipefd[1], "Hello, World", 12);
close(pipefd[1]);
return ret < 0 ? 1 : 0;
} else {
close(pipefd[1]);
if (dup2(pipefd[0], STDIN_FILENO) < 0)
return 1;
execl("/usr/bin/less", "", NULL);
return close(pipefd[0]), 1;
}
}
■ このスレッドは過去ログ倉庫に格納されています