Last active
August 29, 2015 14:10
-
-
Save imasusen/3024cd77d183aa7d631a to your computer and use it in GitHub Desktop.
Revisions
-
imasusen revised this gist
Dec 1, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ int main() { while (read(pipefd[0], buf, bufsize) > 0) { output += buf; // 出力量が多かったら子プロセスを終わらす if (strlen(output.c_str()) > output_limit) { kill(pid, SIGXFSZ); output += "\n出力過多"; -
imasusen revised this gist
Dec 1, 2014 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,9 +10,8 @@ using namespace std; int main() { // パイプ(・㉨・) int pipefd[2]; // 0:read, 1:write pipe2(pipefd, O_CLOEXEC); const int pid = fork(); -
imasusen revised this gist
Dec 1, 2014 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,12 +42,15 @@ int main() { close(pipefd[1]); // 子プロセスが出力してるものを読んでく const int bufsize = 1024; const int output_limit = 128*1024; char buf[bufsize] = ""; std::string output = ""; while (read(pipefd[0], buf, bufsize) > 0) { output += buf; // 出力量が多かったら子プロセスを殺す if (strlen(output.c_str()) > output_limit) { kill(pid, SIGXFSZ); output += "\n出力過多"; -
imasusen revised this gist
Dec 1, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -31,6 +31,7 @@ int main() { old_stderr = dup(STDERR_FILENO); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); while (1) { cout << "a"; } -
imasusen revised this gist
Dec 1, 2014 . 1 changed file with 22 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,44 +4,47 @@ #include <unistd.h> // pipe2, dup, dup2, fork, read, close #include <fcntl.h> // O_CLOEXEC flag #include <signal.h> // kill #include <iostream> #include <string> using namespace std; int main() { int pipefd[2]; // 0:read, 1:write // パイプ pipe2(pipefd, O_CLOEXEC); const int pid = fork(); if (pid == -1) { perror("fork"); return -1; } if (pid == 0) { // 子プロセス close(pipefd[0]); // 標準出力、標準エラーをパイプにリダイレクトさせる int old_stdout, old_stderr; old_stdout = dup(STDOUT_FILENO); old_stderr = dup(STDERR_FILENO); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); while (1) { cout << "a"; } cout << " (^-^)/" << endl; } // 親プロセス close(pipefd[1]); const int bufsize = 1024; const int output_limit = 128*1024; char buf[bufsize] = ""; std::string output = ""; while (read(pipefd[0], buf, bufsize) > 0) { output += buf; if (strlen(output.c_str()) > output_limit) { @@ -51,10 +54,9 @@ int main() { } } close(pipefd[0]); // 子プロセスが出力した内容を表示 cout << output << endl; return 0; } -
imasusen created this gist
Nov 26, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,60 @@ #include <sys/types.h> #include <stdio.h> // perror #include <string.h> // strlen #include <unistd.h> // pipe2, dup, dup2, fork, read, close #include <fcntl.h> // O_CLOEXEC flag #include <signal.h> // kill #include <iostream> #include <string> using namespace std; int main() { int pipefd[2]; // 0:read, 1:write int old_stdout, old_stderr; std::string output = ""; // 標準出力、標準エラーをパイプにリダイレクトさせる pipe2(pipefd, O_CLOEXEC); old_stdout = dup(STDOUT_FILENO); old_stderr = dup(STDERR_FILENO); dup2(pipefd[1], STDOUT_FILENO); dup2(pipefd[1], STDERR_FILENO); const int pid = fork(); if (pid == -1) { perror("fork"); return -1; } if (pid == 0) { // 子プロセス while (1) { cout << "a"; } cout << " (^-^)/" << endl; } // 親プロセス close(pipefd[1]); dup2(old_stdout, STDOUT_FILENO); dup2(old_stderr, STDERR_FILENO); const int bufsize = 1024; char buf[bufsize] = ""; const int output_limit = 128*1024; while (read(pipefd[0], buf, bufsize) > 0) { output += buf; if (strlen(output.c_str()) > output_limit) { kill(pid, SIGXFSZ); output += "\n出力過多"; break; } } close(pipefd[0]); close(old_stdout); close(old_stderr); cout << output << endl; return 0; }