To delay an internal loop inside a RPG program, or to delay a call to another program, use 'sleep' or 'usleep'
H BndDir('QC2LE')
D Sleep Pr 10I 0 ExtProc('sleep')
D Seconds 10U 0 Value
D Usleep Pr 10I 0 ExtProc('usleep')
D Microsecs 10U 0 Value
* Sleep for 30 seconds
C CallP Sleep(0030)
* Sleep for 30 seconds
C CallP Usleep(0030000000)
Note from Chris:
It's working now. Thanks. My testing shows that 1000000 is valid for usleep (it does
the delay). And values over 1000000 don't delay and the return value is zero, not -1.
Note from Mel:
My testing showed the same results as yours.
That is, for values <= 1,000,000, usleep sleeps that many microseconds and returns 0.
For values > 1,000,000, it sleeps 0 microseconds and returns 0. Although the documentation says
it should return -1 and set errno to indicate why it failed, in my testing, both the return value
and the errno were always 0.
Also, the documentation says the return value is an unsigned integer, which would be impossible
for it to return -1. The prototype in QSYSINC/H member UNISTD, defines the return code as int,
which is signed.
Finally, the documentation says the "usleep() function is included for its historical usage.
The setitimer() function is preferred over this function."
So, it appears that both the code and documentation contain errors and we should look at
setitimer() instead.
|