Created
December 28, 2012 07:43
-
-
Save alphaKAI/4395538 to your computer and use it in GitHub Desktop.
fork関数つかって簡単なカウントダウンしてEnterが押されたら終了するプログラム書いてみた
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 characters
| #include <stdio.h> | |
| #include <unistd.h> | |
| #include <signal.h> | |
| int main(void){ | |
| int p_id; | |
| int status; | |
| int return_code = 0; | |
| int i; | |
| int c; | |
| if ((p_id = fork()) == 0){ | |
| for(i=1;i<10;i++){ | |
| printf("%d\n", i); | |
| sleep(1); | |
| } | |
| } | |
| else { | |
| if (p_id != -1) { | |
| c=getchar(); | |
| kill(p_id,SIGKILL); | |
| printf("EXIT\n"); | |
| } | |
| else{ | |
| printf("ERROR:\n%d\n", p_id); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment