#include #include // for sleep. #include // for signal, don't worry about this yet. using namespace std; // Don't worry too much about this yet. static void Handler(int) { cout << "\t\tBRRRRRIIIINNNNGGGGG!!!!!!!!" << endl; return; } int main(int argc, char * argv[]) { unsigned long int napTime = 5; if (argc > 1) { napTime = static_cast (atoi(argv[1])); } // bad, there are better ways to do this. // Don't worry about this for now. // This is for demo purposes only. signal(SIGUSR1, Handler); pid_t mypid = getpid(); cout << "Hello, this is process " << mypid << endl; do { cout << "\tTrying to sleep for " << napTime << endl; napTime = sleep(napTime); if (napTime > 0) { cout << "\tShoot, someone got me up early, " << napTime << " still to sleep" << endl; cout << endl; } } while (napTime > 0); cout << "All done sleeping " << endl; return 0; }