csci4061/lab03-code/sleep_die.c

26 lines
489 B
C
Raw Normal View History

2018-01-29 23:28:37 +00:00
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
// usage: sleep_die secs
//
// Sleep for given number of seconds then raise SIGINT which will
// cause the program to die.
int main(int argc, char *argv[]){
int secs = atoi(argv[1]);
struct timespec tm = {
.tv_nsec = 0,
.tv_sec = secs,
};
nanosleep(&tm,NULL);
printf("O happy dagger! This is thy sheath;\n");
printf("there rust, and let me die.\n");
raise(SIGINT);
return secs;
}