Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <unistd.h>
- #include <time.h>
- #include <sys/time.h>
- #include <signal.h>
- #include <sys/wait.h>
- int i=0;
- void handsofblue(int twobytwo)
- {
- printf("Guy killed me, Mal. Killed me with a sword. How weird is that?\n");
- _exit(1);
- }
- void main(){
- signal(SIGTERM, handsofblue);
- printf("I has a bukkit!\n");
- char *s="Parent:"; int pid;
- while(i<51)
- {
- if(i<26){
- usleep(300000);
- printf("%s globvar:%d, my pid:%d\n",s, i++,getpid());
- if(i==9 ){
- s = (pid=fork())? "Parent:":"Child:";
- srand(time(NULL)+getpid());
- }
- }
- else{
- long vartime = (rand() % 400 +100)*1000;
- printf("%s globvar:%d, waited for: %dms, my pid: %d\n", s, i, (int)vartime/1000, getpid());
- i++;
- usleep(vartime);
- }
- }
- //if(pid){ //wait 4 child
- //waitpid(pid, &i, 0);
- //}
- if(pid) { // kill teh child
- waitpid(pid, &i, 1);
- if(!WIFEXITED(i)){kill(pid,SIGTERM);}
- }
- printf("%s HALP! They be stealing mah bukkit!\n", s);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement