feroz haider
feroz haider

Reputation: 29

Program in C gives 0sec user time and system time

please explain why the user and system time output is zero seconds and 0% cpu usage.

#include <unistd.h> 
#include <sys/stat.h> 
#include <fcntl.h> 
#include <stdlib.h>  

int main() { 
    char c;
    int in, out; 

    in = open(“inputfile_name”, O_RDONLY); 
    out = open(“outputfile_name”, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);  

    while(read(in,&c,1) == 1) 
        write(out,&c,1);

    exit(0);
}

Upvotes: 1

Views: 81

Answers (1)

fuz
fuz

Reputation: 93044

If a program runs sufficiently fast, it may terminate before the long-term system clock (as queried with gettimeofday advances. On some systems, this clock has a precision of just 10 ms, so it's likely that this happens with a very brief program like yours. In this situation, the operating system reports the runtime of your program as 0 as it didn't take any time to run from the point of view of gettimeofday.

Upvotes: 2

Related Questions