On 06/03/2014 11:53 AM, Mohammad Merajul Islam Molla wrote:
Hello,
I noticed some odd behaviors with idlestate.c/execute() function.
I wrote a sample program hello.c with infinite loop -
int main() { while(1); }
#sudo ../idlestat/idlestat -o /tmp/myoutput ../temp/hello idlestat never terminates, because there is no alarm set, hello
program never terminates.
Right, this is the expected behavior.
If I change and invoke idlestat with below command - #sudo ../idlestat/idlestat -o /tmp/myoutput -t 5 ../temp/hello idlestat outputs only below line and exits -
Total trace buffer: 153896 kB
The running program is not sleeping at all, so the cpu is no going to sleep, so no idle traces. Do you have more traces if you do:
int main() { sleep(3600); }
?
What is happening is the below check fails - if (WIFSIGNALED(status) && WTERMSIG(status) == SIGTERM) { return 0; } here condition is always false. Because the status variable was
fetched before killing the process. So status does not contain valid signal number.
if (waitpid(pid, &status, 0) < 0) { if (errno != EINTR || !sigalrm) goto again; kill(pid, SIGTERM); } Possible Fix: call waitpid again after kill and fetch new status.
Right, it should be:
again: if (waitpid(pid, &status, 0) < 0) { if (errno == EINTR && sigalrm) kill(pid, SIGTERM); goto again; }
The below check makes idlestat dependent on the hello program run -
if (WIFEXITED(status) && !WEXITSTATUS(status)) { }
If my program is written to return a non-zero value, the second
condition will be always false.
So with the below program - int main() { return 1; } idlestat outputs only since WEXITSTATUS(status) returns nonzero
value - Total trace buffer: 153896 kB
Possible Fix: Just check WIFEXITED(status) and ommit the fetching of exit status.
Right may be print the exit status of the running program should suffice instead of propagating the error code.
In any case, it should not be allowed to run idlestat with "-t 0", since that will results in problem 1 again.
-- Thanks,
- Meraj