I would like to measure the CPU and User time passed between starting a process and sending SIGINT
signal using C times
function.
However, on print I just get 0
. Can't see the problem..
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/times.h>
#include <signal.h>
struct tms time_start;
struct tms time_end;
clock_t start;
clock_t end;
void handle() {
times(&time_end);
end = time_end.tms_stime;
}
int main(int argc, char *argv[]) {
signal(SIGINT, handle);
times(&time_start);
start = time_start.tms_utime;
pause();
printf("end: %ld, start: %ld\n", (long) end, (long) start);
return 0;
}
This is the output I get:
k@sc:dir$ ./my_time
^Cend: 0, start: 0