381 lines
10 KiB
HTML
381 lines
10 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>setitimer()--Set Value for Interval Timer</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 error condition cleanup on 04/30/02 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>setitimer()--Set Value for Interval Timer</h2>
|
|
|
|
<div class="box" style="width: 50%;">
|
|
<br>
|
|
Syntax<br>
|
|
<pre>
|
|
#include <sys/time.h>
|
|
|
|
int setitimer( int <em>which</em>,
|
|
const struct itimerval <em>*value</em>,
|
|
struct itimerval <em>*ovalue</em> );
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QP0SSRV1<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>setitimer()</strong> function sets the timer specified by <em>
|
|
which</em> to the value in the structure pointed to by <em>value</em> and
|
|
stores the previous value of the timer in the structure pointed to by <em>
|
|
ovalue</em>.</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>which</em></strong></dt>
|
|
|
|
<dd>(Input) The interval timer type.
|
|
|
|
<p>The possible values for <em>which</em>, which are defined in the
|
|
<<strong>sys/time.h</strong>> header file, are as follows:</p>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="20 80" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>ITIMER_REAL</em></td>
|
|
<td align="left" valign="top">The interval timer value is decremented in real
|
|
time. The SIGALRM signal is generated for the process when this timer
|
|
expires.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>ITIMER_VIRTUAL</em></td>
|
|
<td align="left" valign="top">The interval timer value is only decremented when
|
|
the process is running. The SIGVTALRM signal is generated for the process when
|
|
this timer expires.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>ITIMER_PROF</em></td>
|
|
<td align="left" valign="top">The interval timer value is only decremented when
|
|
the process is running or when the system is running on behalf of the process.
|
|
The SIGPROF signal is generated for the process when this timer expires.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>value</em></strong></dt>
|
|
|
|
<dd>(Input) A pointer to the interval timer structure to be used to change the
|
|
interval timer value.
|
|
|
|
<p>The timer value is defined by the itimerval structure. If <em>
|
|
it_value</em> is non-zero, it indicates the time to the next timer expiration.
|
|
If <em>it_interval</em> is non-zero, it indicates the time to be used to
|
|
reset the timer when the <em>it_value</em> time elapses. If <em>
|
|
it_value</em> is zero, the timer is disabled and the value of <em>
|
|
it_interval</em> is ignored. If <em>it_interval</em> is zero, the timer is
|
|
disabled after the next timer expiration.</p>
|
|
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><strong><em>ovalue</em></strong></dt>
|
|
|
|
<dd>(Output) A pointer to the space where the previous interval timer value is
|
|
stored. This value may be NULL.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="5 95" -->
|
|
<tr>
|
|
<td align="left" valign="top"><em>0</em></td>
|
|
<td align="left" valign="top"><strong>setitimer()</strong> was successful.</td>
|
|
</tr>
|
|
|
|
<tr>
|
|
<td align="left" valign="top"><em>-1</em></td>
|
|
<td align="left" valign="top"><strong>setitimer()</strong> was not successful.
|
|
The <em>errno</em> variable is set to indicate the error.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br>
|
|
<br>
|
|
<h3>Error Conditions</h3>
|
|
|
|
<p>If <strong>setitimer()</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>[EINVAL]</em></dt>
|
|
|
|
<dd>
|
|
<p>The value specified for the argument is not correct.</p>
|
|
|
|
<p>A function was passed incorrect argument values, or an operation was
|
|
attempted on an object and the operation specified is not supported for that
|
|
type of object.</p>
|
|
|
|
<p>An argument value is not valid, out of range, or NULL.</p>
|
|
|
|
<ul>
|
|
<li>The value of <em>which</em> is not equal to one of the defined
|
|
values.</li>
|
|
|
|
<li>The <em>tv_usec</em> member of the <em>it_value</em> structure has a
|
|
value greater than or equal to 1,000,000.</li>
|
|
|
|
<li>The <em>tv_usec</em> member of the <em>it_interval</em> structure has a
|
|
value greater than or equal to 1,000,000.</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</dd>
|
|
|
|
<dt><em>[ENOSYSRSC]</em></dt>
|
|
|
|
<dd>
|
|
<p>System resources not available to complete request.</p>
|
|
|
|
<ul>
|
|
<li>The ITIMER_VIRTUAL value for <em>which</em> is not supported on this
|
|
implementation.</li>
|
|
|
|
<li>The ITIMER_PROF value for <em>which</em> is not supported on this
|
|
implementation.</li>
|
|
</ul>
|
|
|
|
<br>
|
|
</dd>
|
|
|
|
<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>
|
|
|
|
<br>
|
|
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
|
|
|
|
<p>The <strong>setitimer()</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>setitimer()</strong> is not
|
|
successful, and an [ENOTSIGINIT] error is returned.</p>
|
|
|
|
<br>
|
|
<h3>Related Information</h3>
|
|
|
|
<ul>
|
|
<li>The <<strong>sys/time.h</strong>> file (see <a href="unix13.htm">
|
|
Header Files for UNIX-Type Functions</a>)<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigalarm.htm">alarm()</a>--Set Schedule for Alarm Signal<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="setitime.htm">setitimer()</a>--Set Value for Interval Timer<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 returns the current interval timer value using the
|
|
<strong>setitimer()</strong> function:</p>
|
|
|
|
<pre>
|
|
#include <sys/time.h>
|
|
#include <signal.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <errno.h>
|
|
|
|
#define LOOP_LIMIT 1E12
|
|
|
|
volatile int sigcount=0;
|
|
|
|
void catcher( int sig ) {
|
|
|
|
struct itimerval value;
|
|
int which = ITIMER_REAL;
|
|
|
|
printf( "Signal catcher called for signal %d\n", sig );
|
|
sigcount++;
|
|
|
|
if( sigcount > 1 ) {
|
|
|
|
/*
|
|
* Disable the real time interval timer
|
|
*/
|
|
|
|
getitimer( which, &value );
|
|
|
|
value.it_value.tv_sec = 0;
|
|
value.it_value.tv_usec = 0;
|
|
|
|
setitimer( which, &value, NULL );
|
|
}
|
|
}
|
|
|
|
int main( int argc, char *argv[] ) {
|
|
|
|
int result = 0;
|
|
|
|
struct itimerval value, ovalue, pvalue;
|
|
int which = ITIMER_REAL;
|
|
|
|
struct sigaction sact;
|
|
volatile double count;
|
|
time_t t;
|
|
|
|
sigemptyset( &sact.sa_mask );
|
|
sact.sa_flags = 0;
|
|
sact.sa_handler = catcher;
|
|
sigaction( SIGALRM, &sact, NULL );
|
|
|
|
getitimer( which, &pvalue );
|
|
|
|
/*
|
|
* Set a real time interval timer to repeat every 200 milliseconds
|
|
*/
|
|
|
|
value.it_interval.tv_sec = 0; /* Zero seconds */
|
|
value.it_interval.tv_usec = 200000; /* Two hundred milliseconds */
|
|
value.it_value.tv_sec = 0; /* Zero seconds */
|
|
value.it_value.tv_usec = 500000; /* Five hundred milliseconds */
|
|
|
|
result = setitimer( which, &value, &ovalue );
|
|
|
|
/*
|
|
* The interval timer value returned by setitimer() should be
|
|
* identical to the timer value returned by getitimer().
|
|
*/
|
|
|
|
if( ovalue.it_interval.tv_sec != pvalue.it_interval.tv_sec ||
|
|
ovalue.it_interval.tv_usec != pvalue.it_interval.tv_usec ||
|
|
ovalue.it_value.tv_sec != pvalue.it_value.tv_sec ||
|
|
ovalue.it_value.tv_usec != pvalue.it_value.tv_usec ) {
|
|
printf( "Real time interval timer mismatch\n" );
|
|
result = -1;
|
|
}
|
|
|
|
|
|
time( &t );
|
|
printf( "Before loop, time is %s", ctime(&t) );
|
|
|
|
for( count=0; ((count<LOOP_LIMIT) && (sigcount<2)); count++ );
|
|
|
|
time( &t );
|
|
printf( "After loop, time is %s\n", ctime(&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( result );
|
|
}
|
|
|
|
</pre>
|
|
|
|
<br>
|
|
<h3>Output:</h3>
|
|
|
|
<pre>
|
|
Before loop, time is Sun Jun 15 10:14:00 1997
|
|
Signal catcher called for signal 14
|
|
Signal catcher called for signal 14
|
|
After loop, time is Sun Jun 15 10:14:01 1997
|
|
The signal catcher gained control
|
|
The value of count is 702943
|
|
</pre>
|
|
|
|
<br>
|
|
<hr>
|
|
API introduced: V4R2
|
|
|
|
<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>
|
|
|