Skip to content

Instantly share code, notes, and snippets.

@Lerc
Created May 29, 2013 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lerc/5667065 to your computer and use it in GitHub Desktop.
Save Lerc/5667065 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
void sig_handler(int sig) {exit(0);};
int main () {
signal(SIGTERM,sig_handler);
pid_t pid_v;
char* result = "heads\0tails";
pid_v=fork();
if(!pid_v) {
pid_v=getppid();
result+=6;
}
srandom(pid_v);
usleep(random() &0xffff);
kill(pid_v,SIGTERM);
puts(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment