302 lines
8.5 KiB
HTML
302 lines
8.5 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>sleep()--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 html cleanup on 04/29/02 by JET -->
|
|
<!--End Header Records -->
|
|
<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>sleep()--Suspend Processing for Interval of Time</h2>
|
|
|
|
<div class="box" style="width: 60%;">
|
|
<br>
|
|
Syntax<br>
|
|
<pre>
|
|
#include <unistd.h>
|
|
|
|
unsigned int sleep( unsigned int <em>seconds</em> );
|
|
</pre>
|
|
|
|
<br>
|
|
Service Program Name: QPOSSRV1<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Default Public Authority: *USE<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
Threadsafe: Yes<br>
|
|
<!-- iddvc RMBR -->
|
|
<br>
|
|
</div>
|
|
|
|
<p>The <strong>sleep()</strong> function suspends a thread for a specified
|
|
number of <em>seconds</em>. (Because of processor delays, the thread can sleep
|
|
slightly longer than this specified time.) If an unblocked signal is received
|
|
during this time and its action is to call a signal-catching function, to end
|
|
the request, or to end the process, <strong>sleep()</strong> returns
|
|
immediately with the amount of sleep time remaining.</p>
|
|
|
|
<p>If a SIGALRM signal is generated for the calling process while <strong>
|
|
sleep()</strong> is running and if the SIGALRM signal is being ignored or
|
|
blocked from delivery, <strong>sleep()</strong> does not return when the
|
|
SIGALRM signal is scheduled. If the SIGALRM signal is blocked from delivery,
|
|
the SIGALRM remains pending after <strong>sleep()</strong> returns.</p>
|
|
|
|
<p>If a SIGALRM signal is generated for the calling process while <strong>
|
|
sleep()</strong> is running (except as a result of a previous call to <strong>
|
|
alarm()</strong>) and if the SIGALRM is not being ignored or blocked from
|
|
delivery, the SIGALRM signal has no effect on <strong>sleep()</strong> other
|
|
than causing it to return.</p>
|
|
|
|
<p>A signal-catching function that interrupts <strong>sleep()</strong> can
|
|
examine and change the time a SIGALRM is scheduled to be generated, the action
|
|
associated with the SIGALRM signal, and whether SIGALRM is blocked from
|
|
delivery.</p>
|
|
|
|
<p>If a signal-catching function interrupts <strong>sleep()</strong> and calls
|
|
<strong>siglongjmp()</strong> or <strong>longjmp()</strong> to restore an
|
|
environment saved prior to <strong>sleep()</strong>, the <strong>
|
|
sleep()</strong> function is canceled. The action associated with the SIGALRM
|
|
signal and the time at which a SIGALRM signal is scheduled to be generated are
|
|
unchanged. The SIGALRM blocking action remains unchanged, unless the thread's
|
|
signal mask is restored as part of the environment.</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 for which the process is to be
|
|
suspended.</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Return Value</h3>
|
|
|
|
<table cellpadding="5">
|
|
<!-- cols="10 90" -->
|
|
<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>value</em></td>
|
|
<td align="left" valign="top">The thread did not sleep the full time because of
|
|
a signal whose action is to run a signal-catching function, to end the request,
|
|
or to terminate the process. The value returned is the number of seconds
|
|
remaining in the specified sleep time; that is, the value of <em>seconds</em>
|
|
minus the actual number of seconds that the thread was suspended.</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>sleep()</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.<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li>The signal function is being called when the system signal controls have
|
|
not been initialized.</li>
|
|
</ul>
|
|
</dd>
|
|
|
|
<dt><em>[ETIMEDOUT]</em></dt>
|
|
|
|
<dd>
|
|
<p>A remote host did not respond within the timeout period.</p>
|
|
</dd>
|
|
|
|
<dt><em>[EWOULDBLOCK]</em></dt>
|
|
|
|
<dd>
|
|
<p>Operation would have caused the process to be suspended.</p>
|
|
|
|
<p>The current thread state would prevent the signal function from
|
|
completing.</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
<br>
|
|
<h3>Usage Notes</h3>
|
|
|
|
<p>The <strong>sleep()</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>sleep()</strong> is not
|
|
successful, and an [ENOTSIGINIT] error is returned.</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="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="sigactn.htm">sigaction()</a>--Examine and Change Signal Action<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="siglngj.htm">siglongjmp()</a>--Perform Nonlocal Goto with Signal
|
|
Handling<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigsetj.htm">sigsetjmp()</a>--Set Jump Point for Nonlocal Goto<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigsusp.htm">sigsuspend()</a>--Wait for Signal<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigtwait.htm">sigtimedwait()</a>--Synchronously Accept a Signal
|
|
for Interval of Time<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigwait.htm">sigwait()</a>--Synchronously Accept a Signal<br>
|
|
<br>
|
|
</li>
|
|
|
|
<li><a href="sigwaiti.htm">sigwaitinfo()</a>--Synchronously Accept a Signal and
|
|
Signal Data<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 uses the <strong>sleep()</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\n", str, ctime(&t) );
|
|
}
|
|
|
|
int main( int argc, char *argv[] ) {
|
|
|
|
unsigned int ret;
|
|
|
|
timestamp( "before sleep()" );
|
|
ret = sleep( 10 );
|
|
timestamp( "after sleep()" );
|
|
|
|
printf( "sleep() returned %d\n", ret );
|
|
|
|
return( 0 );
|
|
}
|
|
</pre>
|
|
|
|
<br>
|
|
<h3>Output:</h3>
|
|
|
|
<pre>
|
|
before sleep() the time is Sun Jan 22 17:25:17 1995
|
|
after sleep() the time is Sun Jan 22 17:25:28 1995
|
|
sleep() returned 0
|
|
</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>
|
|
|