Skip to content

Instantly share code, notes, and snippets.

@Hikari9
Created March 7, 2016 06:04
Show Gist options
  • Save Hikari9/2e40962d296ae004a036 to your computer and use it in GitHub Desktop.
Save Hikari9/2e40962d296ae004a036 to your computer and use it in GitHub Desktop.
For CS162 lab 6
#include <iostream>
#include <cstdio>
#include <ctime>
#include <unistd.h>
using namespace std;
char buffer[26];
int main() {
int child = fork();
if (child < 0) {
printf("Error occured :(\n");
return 1;
} else if (child) {
if (execl("/usr/bin/xclock", "myXclock", NULL) != 0) {
printf("Xclock failed.");
return 2;
}
}
else { // parent
for (int pdate = 1;; ++pdate) {
time_t now = time(NULL);
strftime(buffer, 26, "[%Y-%m-%d] %H:%M:%S", localtime(&now));
printf("%s\n", buffer);
if (pdate % 3 == 0)
printf("\"This program has gone on for far too long. Type Ctrl+C to abort this silly application.\"\n");
sleep(10);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment