Can I use signals for timed input?
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > Can I use signals for timed input?




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Can I use signals for timed input?  
Mark Hobley


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-06 11:10 PM

In alt.comp.os.linux Bill Marcum <bmarcum@iglou.com> wrote:

> I think you've got that backward:

It's not actually working code, just a concept really at the moment, I'm
toying with a few project ideas.

I thought maybe I could background the sleep command, to produce a signal on
completion.

On detection of this signal, I could take some action.

I didn't want to background the slowprocess.

What about if I wanted to obtain user input?

Could I abort the input process if the data was not entered in time?

Even better, could I reset the timer, if a user suddenly started typing?

Regards,

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Telephone: (0121) 247 1596
International: 0044 121 247 1596

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/






[ Post a follow-up to this message ]



    Re: Can I use signals for timed input?  
Roger Leigh


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
01-22-06 11:10 PM

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

[I'm reading this in comp.unix.programmer, and hence assuming you are
using the SUS/POSIX API with C or C++, but looking at the other
newsgroups this originated in, I may be mistaken, in which case I
apologise for the confusion.]

markhobley@hotpop.deletethisbit.com (Mark Hobley) writes:

> In alt.comp.os.linux Bill Marcum <bmarcum@iglou.com> wrote:
>
> What about if I wanted to obtain user input?
>
> Could I abort the input process if the data was not entered in time?

Yes.  Consider that system calls can be interrupted by signals (this
can be specified by using sigaction and omitting SA_RESTART to disable
the restarting of interrupted system calls).  Therefore, if you use
alarm or setitimer to trigger a SIGALRM at some point in the future, a
read() call will be stopped, and you can detect that.  (The signal
handler can be empty in this instance; we are just using it as a means
of interrupting the user input).

See
http://cvs.alioth.debian.org/cgi-bi...ot=buildd-tools
for a simple example of this.  This is for simple username/password
entry (it's a PAM conversation wrapper), and relies upon the
terminal/termios line buffering.  Two separate timeouts are
implemented: a warning timeout and a final fatal timeout.

> Even better, could I reset the timer, if a user suddenly started typing?

Yes.  However, you'll need to disable line buffering by tweaking the
termios for the controlling tty, so that you get input
character-by-character instead of line-by-line.  I would recommend
using setitimer rather than alarm in this instance, so you can
continually adjust the timer with finer accuracy.  You might need to
handle erase/del/bs if you wish to allow the user to correct the
input, or perhaps use ncurses in this instance.


Regards,
Roger

- --
Roger Leigh
Printing on GNU/Linux?  http://gutenprint.sourceforge.net/
Debian GNU/Linux        http://www.debian.org/
GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>

iD8DBQFD03csVcFcaSW/uEgRArvKAJ9CTSCSNvIOihEmm/EMfkND2cpL5ACdHIUS
cG6XmPcldbvtdhbFmrOS3PQ=
=BPB0
-----END PGP SIGNATURE-----





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:13 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register