ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/sigalarm.htm

272 lines
7.1 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
<title>alarm()--Set Schedule for Alarm Signal</title>
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<!-- Begin Header Records ========================================== -->
<!-- UNIX5 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!--End Header Records -->
<!-- Edited by Kersten Feb 02 -->
<!-- This file has undergone html cleanup May 2002 by JET -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<a name="Top_Of_Page"></a>
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<h2>alarm()--Set Schedule for Alarm Signal</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;unistd.h&gt;
unsigned int alarm( unsigned int <em>seconds</em> );
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QPOSSRV1<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: Yes<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>alarm()</strong> function generates a SIGALRM signal after the
number of seconds specified by the <em>seconds</em> parameter have elapsed. The
delivery of the SIGALRM signal is directed at the calling process.</p>
<p><em>seconds</em> is the number of real seconds to elapse before the SIGALRM
is generated. Because of processor delays, the SIGALRM may be generated
slightly later than this specified time. If <em>seconds</em> is zero, any
previously set alarm request is canceled.</p>
<p>Only one such alarm can be active at a time for the process. If a new alarm
time is set, any previous alarm is canceled.</p>
<br>
<!-- Please NOTE: DO NOT DELETE THIS SECTION if this API has no authorities and locks. -->
<!-- Instead, use the commented out coding below to indicate NONE. -->
<h3>Authorities and Locks</h3>
<!-- Use this if there are no authorities and locks. -->
<p>None.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong><em>seconds</em></strong></dt>
<dd>(Input) The number of real seconds to elapse before generating the
signal.</dd>
</dl>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="10 90" -->
<tr>
<td align="left" valign="top"><em>value</em></td>
<td align="left" valign="top"><strong>alarm()</strong> was successful. The
value returned is one of the following:
<ul>
<li>A nonzero value that is the number of real seconds until the previous
<strong>alarm()</strong> request would have generated a SIGALRM signal.</li>
<li>A value of zero if there was no previous <strong>alarm()</strong> request
with time remaining.</li>
</ul>
</td>
</tr>
<tr>
<td align="left" valign="top"><em>-1</em></td>
<td align="left" valign="top"><strong>alarm()</strong> was not successful. The
<em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<h3>Error Conditions</h3>
<p>If <strong>alarm()</strong> is not successful, <em>errno</em> usually
indicates the following error. Under some conditions, <em>errno</em> could
indicate an error other than that listed here.</p>
<dl>
<dt><em>[ENOTSIGINIT]</em></dt>
<dd>
<p>Process not enabled for signals.</p>
<p>An attempt was made to call a signal function under one of the following
conditions:</p>
<ul>
<li>The signal function is being called for a process that is not enabled for
asynchronous signals.</li>
<li>The signal function is being called when the system signal controls have
not been initialized.</li>
</ul>
<br>
</dd>
</dl>
<h3>Usage Notes</h3>
<p>The <strong>alarm()</strong> function enables a process for signals if the
process is not already enabled for signals. For details, see <a href=
"sigesig.htm">Qp0sEnableSignals()--Enable Process for Signals</a>. If the
system has not been enabled for signals, <strong>alarm()</strong> is not
successful, and an [ENOTSIGINIT] error is returned.</p>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>signal.h</strong>&gt; file (see <a href="unix13.htm">Header
Files for UNIX-Type Functions</a>)<br>
<br>
</li>
<li>The &lt;<strong>unistd.h</strong>&gt; file<br>
<br>
</li>
<li><a href="sigpause.htm">pause()</a>--Suspend Process Until Signal
Received<br>
<br>
</li>
<li><a href="sigdsig.htm">Qp0sDisableSignals()</a>--Disable Process for
Signals<br>
<br>
</li>
<li><a href="sigesig.htm">Qp0sEnableSignals()</a>--Enable Process for
Signals<br>
<br>
</li>
<li><a href="setitime.htm">setitimer()</a>--Set Value for Interval Timer<br>
<br>
</li>
<li><a href="sigactn.htm">sigaction()</a>--Examine and Change Signal Action<br>
<br>
</li>
<li><a href="sigsusp.htm">sigsuspend()</a>--Wait for Signal<br>
<br>
</li>
<li><a href="sigsleep.htm">sleep()</a>--Suspend Processing for Interval of
Time<br>
<br>
</li>
<li><a href="usleep.htm">usleep()</a>--Suspend Processing for Interval of
Time</li>
</ul>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example generates a SIGALRM signal using the <strong>
alarm()</strong> function:</p>
<pre>
#include &lt;signal.h&gt;
#include &lt;unistd.h&gt;
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;errno.h&gt;
#define LOOP_LIMIT 1E6
volatile int sigcount=0;
void catcher( int sig ) {
printf( "Signal catcher called for signal %d\n", sig );
sigcount = 1;
}
int main( int argc, char *argv[] ) {
struct sigaction sact;
volatile double count;
time_t t;
sigemptyset( &amp;sact.sa_mask );
sact.sa_flags = 0;
sact.sa_handler = catcher;
sigaction( SIGALRM, &amp;sact, NULL );
alarm(5); /* timer will pop in five seconds */
time( &amp;t );
printf( "Before loop, time is %s", ctime(&amp;t) );
for( count=0; ((count&lt;LOOP_LIMIT) &amp;&amp; (sigcount==0)); count++ );
time( &amp;t );
printf( "After loop, time is %s\n", ctime(&amp;t) );
if( sigcount == 0 )
printf( "The signal catcher never gained control\n" );
else
printf( "The signal catcher gained control\n" );
printf( "The value of count is %.0f\n", count );
return( 0 );
}
</pre>
<br>
<h3>Output:</h3>
<pre>
Before loop, time is Sun Jan 22 10:14:00 1995
Signal catcher called for signal 14
After loop, time is Sun Jan 22 10:14:05 1995
The signal catcher gained control
The value of count is 290032
</pre>
<br>
<hr>
API introduced: V3R6
<hr>
<center>
<table cellpadding="2" cellspacing="2">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
</tr>
</table>
</center>
</body>
</html>