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

331 lines
8.5 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!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>getitimer()--Get Value for Interval Timer</title>
<!-- Begin Header Records ========================================== -->
<!-- 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. -->
<!-- Change History: -->
<!-- UNIX5 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
<!-- 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>
<!--End Header Records -->
<!-- Java sync-link -->
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
</script>
<a name="Top_Of_Page"></a>
<h2>getitimer()--Get Value for Interval Timer</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<pre>
#include &lt;sys/time.h&gt;
int getitimer( int <em>which</em>, struct itimerval <em>*value</em> );
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QP0SSRVI<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>getitimer()</strong> function returns the value last used to set
the interval timer specified by <em>which</em> in the structure pointed to by
<em>value</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
&lt;<strong>sys/time.h</strong>&gt; 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>(Output) A pointer to the space where the current interval timer value is
stored.</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>getitimer()</strong> was successful.</td>
</tr>
<tr>
<td align="left" valign="top"><em>-1</em></td>
<td align="left" valign="top"><strong>getitimer()</strong> was not successful.
The <em>errno</em> variable is set to indicate the error.</td>
</tr>
</table>
<br>
<h3>Error Conditions</h3>
<p>If <strong>getitimer()</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 compact>
<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>
</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>
</dd>
</dl>
<br>
<h3>Related Information</h3>
<ul>
<li>The &lt;<strong>sys/time.h</strong>&gt; 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>getitimer()</strong> function:</p>
<pre>
#include &lt;sys/time.h&gt;
#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 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 &gt; 1 ) {
/*
* Disable the real time interval timer
*/
getitimer( which, &amp;value );
value.it_value.tv_sec = 0;
value.it_value.tv_usec = 0;
setitimer( which, &amp;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( &amp;sact.sa_mask );
sact.sa_flags = 0;
sact.sa_handler = catcher;
sigaction( SIGALRM, &amp;sact, NULL );
getitimer( which, &amp;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, &amp;value, &amp;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( &amp;t );
printf( "Before loop, time is %s", ctime(&amp;t) );
for( count=0; ((count&lt;LOOP_LIMIT) &amp;&amp; (sigcount&lt;2)); 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( 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>