The man page for ocount says "you must stop it in a controlled manner so that the data collection process can be shut down cleanly and final results can be displayed. Use kill -SIGINT <ocount-pid> for this purpose."</ocount-pid>
However, if one attempts to kill ocount very soon after it was started, the kill command will have no effect, and ocount will run forever.
"very soon" is within 1 second. On a test system, it reliably failed at roughly 0.12 seconds, and succeeded at 0.15 seconds.
$ egrep 'sigaction|kill' ocount.ok.strace
21452 rt_sigaction(SIGTSTP, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGTTIN, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGTTOU, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGINT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, {SIG_IGN, [], 0}, 8) = 0
21452 rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTART}, {0x5d812bf0, [], SA_RESTART}, 8) = 0
21452 rt_sigaction(SIGINT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGQUIT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21452 rt_sigaction(SIGINT, {0x10004384, [INT], 0}, NULL, 8) = 0
21452 write(1, "ocount: Press Ctl-c or 'kill -SI"..., 61) = 61
21452 rt_sigaction(SIGCHLD, NULL, {SIG_DFL, [], 0}, 8) = 0
21447 kill(21452, SIGINT) = 0
==
$ egrep 'sigaction|kill' ocount.ko.strace
21492 rt_sigaction(SIGTSTP, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21492 rt_sigaction(SIGTTIN, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21492 rt_sigaction(SIGTTOU, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21492 rt_sigaction(SIGINT, {SIG_DFL, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21492 rt_sigaction(SIGQUIT, {SIG_DFL, [], 0}, {SIG_IGN, [], 0}, 8) = 0
21492 rt_sigaction(SIGCHLD, {SIG_DFL, [], SA_RESTART}, {0x408b2bf0, [], SA_RESTART}, 8) = 0
21492 rt_sigaction(SIGINT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21492 rt_sigaction(SIGQUIT, {SIG_IGN, [], 0}, {SIG_DFL, [], 0}, 8) = 0
21487 kill(21492, SIGINT) = 0
21492 rt_sigaction(SIGINT, {0x10004384, [INT], 0}, NULL, 8) = 0
21492 write(1, "ocount: Press Ctl-c or 'kill -SI"..., 61) = 61
==
I should not that the first 8 of those calls to sigaction come before the "execve" appears, so libc is likely doing those.
Also note that the different task ID which invokes "kill" is external to ocount. The sequence is:
I think the simple solution is to register the signal handler very early in the program.
(apologies for the formatting. the markup grabs my separation characters and makes things into header fonts) If I can edit it, let me know.