Skip to content

Instantly share code, notes, and snippets.

@xals
Last active August 29, 2015 14:01
Show Gist options
  • Save xals/2a853436fbb03c70e45d to your computer and use it in GitHub Desktop.
Save xals/2a853436fbb03c70e45d to your computer and use it in GitHub Desktop.
My fork.
#define _XOPEN_SOURCE
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<unistd.h>
// Main.
int main(int argc, char **argv) {
// Defining variables.
time_t now, target;
struct tm target_tm;
int pid;
const char* target_str;
// Defining the target date.
target_str = "25/10/2014";
// Parsing date.
strptime(target_str, "%d/%m/%Y", &target_tm);
// Convert struct tm into time_t.
target = mktime(&target_tm);
// Wait until the good time.
do {
now = time(NULL);
sleep(1);
} while (difftime(target, now) > 0);
// THE fork.
pid = fork();
// Check PID.
if (pid == 0) {
// Child process.
printf("Waaaaaaa!\n");
} else {
// Parent process.
printf("Happy!\n");
}
// All went fine.
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment