LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to make a free running counter resetable by pressing a key. (http://www.linuxquestions.org/questions/linux-software-2/how-to-make-a-free-running-counter-resetable-by-pressing-a-key-728171/)

stf92 05-24-2009 11:29 AM

How to make a free running counter resetable by pressing a key.
 
Linux kernel 2.16

Hi:
Let clk be the counter. clk is always counting but, when I press a keyboard key it resets itself and starts over from zero. I go to make a coffee and, when coming back and begin typing again, if I also
have variable clk_old, I can know how much time I spent in the kitchen. Ok. The program is almost done but:
1) Can this be done by a script? If so, I'd need the whole script. I not:
2) Is there a signal that interrupts every, say 1s?
3) Please consider I'm new both to linux and to C. In another environment, this would seem a pretty simple program
for me to write.

The only concern, I think, is how to catch the signal and write the handler (only the body). Thanks for reading.

fpmurphy 05-24-2009 11:31 AM

This sounds like homework

stf92 05-24-2009 11:33 AM

I forgot. Compiler: gcc (GCC) 4.1.2.

stf92 05-24-2009 11:39 AM

Beleave me. I'm not. I program since a youngster. Thanks for
reading.

H_TeXMeX_H 05-24-2009 11:41 AM

It's possible to do with a script, likely with awk:
http://www.grymoire.com/Unix/Awk.html#uh-50

stf92 05-24-2009 11:46 AM

Thanks a lot. It's first thing I want do with linux, learning scripts, since I've seen i go nowhere without understanding them. There's also the other alternative. Isolate one self in the language, and all between the compiler and os. Thanks again.


All times are GMT -5. The time now is 05:56 PM.