LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-24-2009, 10:29 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Rep: Reputation: 76
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.
 
Old 05-24-2009, 10:31 AM   #2
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 299

Rep: Reputation: 62
This sounds like homework
 
Old 05-24-2009, 10:33 AM   #3
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
I forgot. Compiler: gcc (GCC) 4.1.2.
 
Old 05-24-2009, 10:39 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
Beleave me. I'm not. I program since a youngster. Thanks for
reading.
 
Old 05-24-2009, 10:41 AM   #5
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
It's possible to do with a script, likely with awk:
http://www.grymoire.com/Unix/Awk.html#uh-50
 
Old 05-24-2009, 10:46 AM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 4,442

Original Poster
Rep: Reputation: 76
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.
 
  


Reply

Tags
counter, programming, signal handler


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to simulate a ENTER key pressing khaos83 Linux - Newbie 2 08-06-2008 04:41 AM
Blank the screen on pressing key: possible? arrenlex Linux - Software 2 12-26-2005 04:09 PM
Pressing 'alt 1' key twantrd Linux - General 2 01-07-2005 12:05 AM
Keyboard issues, pressing and holding key sometimes doesn't have ordinary effect... ateam Slackware 6 11-02-2004 02:52 AM
kde start menu/kmenu position when pressing windows key mickyg Linux - Software 0 10-29-2004 04:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration