hello!
i have to find time in nanosecond of a particular process and for that i am using clock_gettime() function.
i tried different codes i got from net but getting same error
error: ‘CLOCK_PROCESS_CPUTIME_ID’ undeclared (first use in this function)
i have included relavent header file of time also. and complied the whole code that i got from net. that was working fine and giving output.
but when i use some of the relavent code that i need it gives me this error.
plz tell me am i missing something aur using the code in a wrong way?
heres my code!
#include <stdlib.h>
#include <sys/sysinfo.h>
#include <openssl/aes.h>
#include <openssl/crypto.h>
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
struct sysinfo sys_info;
int days, hours, mins;
char send_data[1024];
////code for aes
char *key1="mykey01234567891";
char outs[120];
char decr[120];
AES_KEY fkey1[16];
AES_KEY fkey2[16];
int main () {
// reset the clock
struct timespec tS;
tS.tv_sec = 0;
tS.tv_nsec = 0;
if(sysinfo(&sys_info) != 0)
perror("sysinfo");
// Uptime
days = sys_info.uptime / 86400;
hours = (sys_info.uptime / 3600) - (days * 24);
mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
printf("Uptime: %ddays, %dhours, %dminutes, %ldseconds\n",
days, hours, mins, sys_info.uptime % 60);
sprintf(send_data,"%ddays,%dhours,%dmins", days,hours,mins);
clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tS);
//code to encrypt the messege using AES
AES_set_encrypt_key(key1, 128, fkey1);
AES_encrypt(send_data, outs, fkey1);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tS);
printf("Time taken is: %d and %ld ",tS.tv_sec, tS.tv_nsec);
return 0;
}