Hi is there a method on which I can make my code safe from other OS interrupts etc in Linux GNU? For example if I have the code below and I need to find the exact execution time without other things interrupting my code.
I have already looked into pthread_mutex_lock(&cs_mutex);
but wasn’t able to stop other operations to run.
while(1){ //start some method to block other OS overheads c_start=clock(); some_function(); c_end=clock(); //stop OS overhead block //calculate time }
Advertisement
Answer
You can use clock_gettime:
timespec ts; clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
It won’t prevent other processes interrupting your code but it will only time the execution of your process taking such interrupts into account.