About cookies on this site Our websites require some cookies to function properly (required). In addition, other cookies may be used with your consent to analyze site usage, improve the user experience and for advertising. For more information, please review your options. By visiting our website, you agree to our processing of information as described in IBM’sprivacy statement. To provide a smooth navigation, your cookie preferences will be shared across the IBM web domains listed here.
Troubleshooting
Problem
This document shows how to use the C API usleep() to delay a job for less than a second.
Resolving The Problem
This document shows how to use the C API usleep() to delay a job for less than a second.
The function usleep() is a C API that suspends the current process for the number of microseconds passed to it. It can be used for delaying a job. DLYJOB works well if you are looking to delay a job for more than a second. If you need to delay the job for less than a second, however, you must use the usleep() API. The usleep() API is contained in the service program QSYS/QP0SSRV1. The prototype is as follows:
int usleep( useconds_t useconds );
Where useconds_t is of type unsigned integer. It returns an integer; 0 if successful, -1 if unsuccessful. It can accept anywhere from 0 to 999999 microseconds.
Here are some examples of coding the API in CLLE, ILE RPG IV, and ILE/C. In these examples, the job is delayed for 500,000 microseconds, or 0.5 seconds.
The function usleep() is a C API that suspends the current process for the number of microseconds passed to it. It can be used for delaying a job. DLYJOB works well if you are looking to delay a job for more than a second. If you need to delay the job for less than a second, however, you must use the usleep() API. The usleep() API is contained in the service program QSYS/QP0SSRV1. The prototype is as follows:
int usleep( useconds_t useconds );
Where useconds_t is of type unsigned integer. It returns an integer; 0 if successful, -1 if unsuccessful. It can accept anywhere from 0 to 999999 microseconds.
Here are some examples of coding the API in CLLE, ILE RPG IV, and ILE/C. In these examples, the job is delayed for 500,000 microseconds, or 0.5 seconds.
Caution: The following code snippets are examples only. IBM accepts no responsibility for their correctness. |
ILE RPG IV
**FREE Dcl-Pr USleep Int(10) Extproc('usleep'); MSeconds Uns(10) Value; End-Pr; Dcl-S MSeconds Uns(10) Inz(500000); Dcl-S returnStatus Int(10); returnStatus = USleep(MSeconds); *inLr = *on;
Name the source member USLEEP in the source physical file QRPGLESRC. Compile using the following statements:
CRTRPGMOD MODULE(USLEEP) SRCFILE(QRPGLESRC)
CRTPGM PGM(USLEEP) BNDSRVPGM((QP0SSRV1))
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p000000hB4rAAE","label":"API"},{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
560965705
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
API, Programming ILE Languages
Software version:
All Versions
Operating system(s):
IBM i
Document number:
686545
Modified date:
21 November 2024
UID
nas8N1012283
Manage My Notification Subscriptions