<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Timeout getchar() in C in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305165#M689010</link>
    <description>Excellent... works great!&lt;BR /&gt;thanks for your help</description>
    <pubDate>Thu, 13 Nov 2008 12:19:51 GMT</pubDate>
    <dc:creator>Renda Skandier</dc:creator>
    <dc:date>2008-11-13T12:19:51Z</dc:date>
    <item>
      <title>Timeout getchar() in C</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305162#M689007</link>
      <description>Hi,&lt;BR /&gt; I have a program receiving one character at a time. If nothing is entered for 5 min, I'd like to break out of the loop.&lt;BR /&gt;something like &lt;BR /&gt;while (time(&amp;amp;curtime) - lastsendtime) &amp;lt; 300 )&lt;BR /&gt;  getchar();&lt;BR /&gt;&lt;BR /&gt;unfortunately, this doesn't get to my time check until a char is entered&lt;BR /&gt;Any ideas?&lt;BR /&gt; tia&lt;BR /&gt;</description>
      <pubDate>Wed, 12 Nov 2008 20:17:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305162#M689007</guid>
      <dc:creator>Renda Skandier</dc:creator>
      <dc:date>2008-11-12T20:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Timeout getchar() in C</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305163#M689008</link>
      <description>&lt;!--!*#--&gt;Perhaps you should just use alarm(2)?&lt;BR /&gt;Otherwise you would have to use select(2) and system calls.&lt;BR /&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;#include &lt;SIGNAL.H&gt;&lt;BR /&gt;void got_alarm(int sig) {&lt;BR /&gt;   fprintf(stderr, "Got signal %d\n", sig);&lt;BR /&gt;}&lt;BR /&gt;int main() {&lt;BR /&gt;   alarm(5*60);&lt;BR /&gt;   signal(SIGALRM, got_alarm);&lt;BR /&gt;   int c = getchar();&lt;BR /&gt;   printf("getchar returned %x\n", c);&lt;BR /&gt;   return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Before you get each char, you would have to reenable the alarm.  While not reading, you would have to disable it.&lt;/SIGNAL.H&gt;&lt;/UNISTD.H&gt;&lt;/STDIO.H&gt;</description>
      <pubDate>Wed, 12 Nov 2008 23:32:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305163#M689008</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2008-11-12T23:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: Timeout getchar() in C</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305164#M689009</link>
      <description>&lt;!--!*#--&gt;Hi Renda:&lt;BR /&gt;&lt;BR /&gt;Sending 'alarm()' to SIGALRM works nicely in Perl too when using 'getc()':&lt;BR /&gt;&lt;BR /&gt;Consider this script where I'va added the appropriate signal handler (SIGALRM) and 'alarm()' call to timeout a character read (getc()) after 5-seconds.&lt;BR /&gt;&lt;BR /&gt;The Term::ReadKey Perl module is a compiled C module that offers control over various terminal modes.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Term::ReadKey;&lt;BR /&gt;$SIG{HUP}  = 'IGNORE';&lt;BR /&gt;$SIG{INT}  = 'IGNORE';&lt;BR /&gt;$SIG{QUIT} = 'IGNORE';&lt;BR /&gt;$SIG{ALRM} = sub { ReadMode 'restore'; print STDERR "\nTIMEOUT!\n"; exit 0 };&lt;BR /&gt;$SIG{TERM} = sub { ReadMode 'restore'; exit 0 };&lt;BR /&gt;my $char;&lt;BR /&gt;my @password;&lt;BR /&gt;my $tmout  = 0; #...ARBITRARY...set to 0 to disable...&lt;BR /&gt;print "Enter password: ";&lt;BR /&gt;ReadMode 'noecho';&lt;BR /&gt;ReadMode 'raw';&lt;BR /&gt;alarm $tmout;&lt;BR /&gt;while ( $char = ReadKey 0 ) {&lt;BR /&gt;    last if $char eq "\n";&lt;BR /&gt;    next if ( ord($char) &amp;lt; 040 or ord($char) &amp;gt; 0176 );&lt;BR /&gt;    push( @password, $char );&lt;BR /&gt;    print '*';&lt;BR /&gt;    alarm $tmout;&lt;BR /&gt;}&lt;BR /&gt;ReadMode 'restore';&lt;BR /&gt;print "\n&amp;gt;", @password, "&amp;lt;\n";&lt;BR /&gt;1;&lt;BR /&gt;#_jrf.&lt;BR /&gt;  &lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Thu, 13 Nov 2008 00:55:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305164#M689009</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-11-13T00:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Timeout getchar() in C</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305165#M689010</link>
      <description>Excellent... works great!&lt;BR /&gt;thanks for your help</description>
      <pubDate>Thu, 13 Nov 2008 12:19:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/timeout-getchar-in-c/m-p/4305165#M689010</guid>
      <dc:creator>Renda Skandier</dc:creator>
      <dc:date>2008-11-13T12:19:51Z</dc:date>
    </item>
  </channel>
</rss>

