217 lines
5.6 KiB
HTML
217 lines
5.6 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>usleep()--Suspend Processing for Interval of Time</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 -->
|
||
|
<!-- Edited by Kersten Feb 02 -->
|
||
|
<!-- This file has undergone error condition cleanup on 04/30/02 by JET -->
|
||
|
<!--End Header Records -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
|
||
|
<h2>usleep()--Suspend Processing for Interval of Time</h2>
|
||
|
|
||
|
<div class="box" style="width: 60%;">
|
||
|
<br>
|
||
|
Syntax<br>
|
||
|
<pre>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
unsigned int usleep( useconds_t <em>useconds</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>usleep()</strong> function suspends a thread for the number of
|
||
|
microseconds specified by the of <em>useconds</em> parameter. (Because of
|
||
|
processor delays, the thread can be suspended slightly longer than this
|
||
|
specified time.)</p>
|
||
|
|
||
|
<p>The <strong>usleep()</strong> function uses the process's real-time interval
|
||
|
timer to indicate when the thread should be resumed.</p>
|
||
|
|
||
|
<p>There is one real-time interval timer for each process. The <strong>
|
||
|
usleep()</strong> function will not interfere with a previous setting of this
|
||
|
timer.</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>useconds</em></strong></dt>
|
||
|
|
||
|
<dd>(Input) The number of microseconds for which the thread is to be
|
||
|
suspended.</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">The thread slept for the full time
|
||
|
specified.</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr>
|
||
|
<td align="left" valign="top"><em>-1</em></td>
|
||
|
<td align="left" valign="top"><strong>sleep()</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>usleep()</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>The value specified for the argument is not correct.
|
||
|
|
||
|
<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 time interval specified 1,000,000 or more microseconds.</li>
|
||
|
</ul>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3><a name="USAGE_NOTES">Usage Notes</a></h3>
|
||
|
|
||
|
<p>The <strong>usleep()</strong> function is included for its historical usage.
|
||
|
The <strong>setitimer()</strong> function is preferred over this function.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li>The <<strong>unistd.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="getitime.htm">getitimer()</a>--Get Value for Interval Timer<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</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 uses the <strong>usleep()</strong> function to suspend
|
||
|
processing for a specified time:</p>
|
||
|
|
||
|
<pre>
|
||
|
#include <unistd.h>
|
||
|
#include <stdio.h>
|
||
|
#include <time.h>
|
||
|
|
||
|
void timestamp( char *str ) {
|
||
|
|
||
|
time_t t;
|
||
|
|
||
|
time( &t );
|
||
|
printf( "%s the time is %s\nquot;, str, ctime(&t) );
|
||
|
}
|
||
|
|
||
|
int main( int argc, char *argv[] ) {
|
||
|
|
||
|
int result = 0;
|
||
|
|
||
|
timestamp( quot;before usleep()quot; );
|
||
|
result = usleep( 999999 );
|
||
|
timestamp( quot;after usleep()quot; );
|
||
|
|
||
|
printf( quot;usleep() returned %d\nquot;, result );
|
||
|
|
||
|
return( result );
|
||
|
}
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
<h3>Output:</h3>
|
||
|
|
||
|
<pre>
|
||
|
before usleep() the time is Sun Jun 15 17:25:17 1995
|
||
|
after usleep() the time is Sun Jun 15 17:25:18 1995
|
||
|
usleep() returned 0
|
||
|
</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>
|
||
|
|