Home > Archive > Cobol > September 2004 > How to let a COBOL program sleep 5 seconds
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to let a COBOL program sleep 5 seconds
|
|
| William Cai 2004-09-10, 3:55 pm |
| Hi, folks
Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
COBOL. Sorry for the stupid question. :)
-William
| |
| Robert Wagner 2004-09-10, 3:55 pm |
| On 9 Sep 2004 20:24:23 -0700, "William Cai" <caiwenliang@gmail.com>
wrote:
>Hi, list
>
>I am looking for the solution. Could anybody please tell me how to code
>instead of discussing if sleep is a Cobol standard function? Though
>your dicussion also helps me. :P
>
>Repeat my question.
>I wanna develop a COBOL program. The program will sleep several seconds
>according to user's input.
There are two kinds of sleep:
1. Run in a loop until n seconds have elapsed.
2. Tell the operating system to mark you asleep and wake you in n
seconds.
In human terms, 1. would not be called sleep, it would be called
wasting time. Unfortunately, it is the best you can do in standard
Cobol.
working-storage section.
01 time-now.
10 hours pic 9(02).
10 minutes pic 9(02).
10 seconds pic 9(02).
10 hundredths pic 9(02).
01 time-integer pic 9(09).
01 wakeup-integer pic 9(09).
linkage section.
01 sleep-duration pic 9.
procedure division using sleep-duration.
perform read-clock
compute wakeup-integer = time-integer + (sleep-duration * 100)
perform read-clock until time-integer > wakeup-integer
goback.
read-clock.
accept time-now from time
compute time-integer =
((((hours * 60) + minutes) * 60) + seconds) * 100) + hundredths).
If your compiler supports Events or MultiThreading, find the Wait
function, have the program wait for an event that will never happen or
return an error in n seconds. That would be true sleep, type 2. above.
| |
| Joe Zitzelberger 2004-09-10, 8:55 pm |
| In article <x6qdnYOZU9SRkaPcRVn-pw@giganews.com>,
"JerryMouse" <nospam@bisusa.com> wrote:
> Richard wrote:
>
> Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
> Windows has preemptive multi-tasking and will interrupt a CPU bound job to
> give cycles to other applications.
>
>
And they might get it working correctly in time for Win 2008...
| |
| Robert Wagner 2004-09-11, 3:55 am |
| On Tue, 7 Sep 2004 14:57:56 +0800, "William Cai"
<wenliang_cai@yahoo.com.cn> wrote:
>Update my question:
>
>I list my program as below. But whatever I input, the program will sleep for
>a very long time. I am sure not if the program hangs. Anyone can help? Thank
>you.
>
> IDENTIFICATION DIVISION.
> PROGRAM-ID. EXAM1.
> ENVIRONMENT DIVISION.
> DATA DIVISION.
> WORKING-STORAGE SECTION.
> 77 SLEEP-SEC PIC 9.
> PROCEDURE DIVISION.
> S. DISPLAY 'THIS IS COBOL'.
> DISPLAY 'PLEASE INPUT THE SECONDS FOR SLEEP'.
> ACCEPT SLEEP-SEC.
> DISPLAY 'WILL SLEEP ', SLEEP-SEC, ' SECONDS'.
> CALL "sleep" USING SLEEP-SEC;
> STOP RUN.
>
>"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
>news:chjjss$t76$1@mail.cn99.com...
>Hi, folks
>
>Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
>COBOL. Sorry for the stupid question. :)
Sleep is not a *standard* Cobol function; is it a standard C function.
It appears you're calling the C function. If true, change sleep-sec to
binary pic 9(9) and call using by value sleep-sec.
| |
| Vaclav Snajdr 2004-09-11, 3:55 am |
| I use:
01 SLEEP-TIME PIC 9(9) COMP VALUE 500000.
(OS LINUX IN MY CASE, MF-COBOL)
ACCEPT SOME-NUM-FIELD AT 2479 WITH SIZE 1 AUTO TIMEOUT SLEEP-TIME.
William Cai wrote:
> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new
> to COBOL. Sorry for the stupid question. :)
>
>
> -William
--
Vaclav Snajdr
| |
| Robert Wagner 2004-09-11, 3:55 am |
| On Tue, 7 Sep 2004 14:57:56 +0800, "William Cai"
<wenliang_cai@yahoo.com.cn> wrote:
>Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
>COBOL. Sorry for the stupid question. :)
If my suggested fix works, you might do one or both of the following:
1. Write a prototype of the sleep function in Cobol and put it at the
top of your program. It would have prevented the type mismatch.
Your instructor probably never saw a Cobol prototype. If your compiler
supports this feature (Micro Focus does), you'll get an A.
2. Tell your instructor he's not teaching Cobol when he has you call a
foreign function. You'll have the satisfaction of being right, even
though you'll get a C.
| |
| Robert Wagner 2004-09-11, 3:55 am |
| On Tue, 7 Sep 2004 14:29:25 -0500, "JerryMouse" <nospam@bisusa.com>
wrote:
>Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
>Windows has preemptive multi-tasking and will interrupt a CPU bound job to
>give cycles to other applications.
Correction: starting with Win95.
http://www.microsoft.com/ntworkstat...95/techdiff.asp
| |
| wahlers 2004-09-11, 3:55 pm |
| To add to Frederico Fonseca's answer:
COBOL does not include a "sleep" function up to and including COBOL-85.
There might(!) be a COBOL intrinsic standard function that performs this
function (I don't know...check yourself).
There might(!) be a COBOL standard "sleep" function in the COBOL-2002
standard (or beyond). I don't know!
Assuming there is no standard "sleep" function then do the following:
1. Write a COBOL function (within OOCOBOL: a COBOL static function),
calling a system dependent(!) "sleep" routine.
2. Let your program call this (static) COBOL function when required.
This 2-phase call structure will accomplish the following:
It will prevent a massive recompile of many COBOL programmes in case you
have to change the environment or "sleep" routine.
Thus:
COBOL programs (many) -- calls -> COBOL "sleep" routine (independent) --
calls -> "sleep" routine (system dependent)
Notice that in the worst case scenario the system dependent "sleep"
routine must be replaced and maybe the COBOL "sleep" routine must be
modified (calling a different system dependent "sleep" routine name and/or
parameters).
There is, and will be, only one COBOL "sleep" routine.
The call structure relationship is thus as follows:
many COBOL programs calling 1 COBOL "sleep" routine calling 1 system
dependent "sleep" routine.
Using a construction as described as above makes your system more robust
and more adaptable for change.
I hope I was clear enough...regards, Wim Ahlers.
P.S. I don't care what the system dependent sleep routine looks like
(assembler, C++, LE routines (C), or whatever...).
| |
|
| Although it is not very efficient from a CPU perspective (and not exact,
although many OS sleep's are not exact either), you could do something like:
.....
WORKING-STORAGE SECTION.
01 THE-TIME.
03 THE-TIME-HH PIC 99.
03 THE-TIME-MM PIC 99.
03 THE-TIME-SS PIC 99.
01 FIVE-SECONDS-LATER PIC 99.
....
....
PROCEDURE DIVISION.
....
....
ACCEPT THE-TIME FROM TIME.
ADD THE-TIME-SS, 5 GIVING FIVE-SECONDS-LATER.
IF FIVE-SECONDS-LATER >= 60
SUBTRACT 60 FROM FIVE-SECONDS-LATER.
PERFORM UNTIL THE-TIME-SS = FIVE-SECONDS-LATER
ACCEPT THE-TIME FROM TIME
END-PERFORM.
I did this off the top of my head with no testing (and I don't use this
method in practice), so you may need to tweak....
(The reason this is not exact is ACCEPT FROM TIME could execute in the
middle of a second.)
"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
news:chjjss$t76$1@mail.cn99.com...
> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new
to
> COBOL. Sorry for the stupid question. :)
>
>
> -William
>
>
| |
| William M. Klein 2004-09-12, 8:55 am |
| What compiler and operating system are you running on? I know how to do this on
a few, but it is NOT portable across systems and compilers.
--
Bill Klein
wmklein <at> ix.netcom.com
"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
news:chjjss$t76$1@mail.cn99.com...
> Hi, folks
>
> Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
> COBOL. Sorry for the stupid question. :)
>
>
> -William
>
>
| |
| Richard 2004-09-12, 8:55 am |
| "JerryMouse" <nospam@bisusa.com> wrote
>
> Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
> Windows has preemptive multi-tasking and will interrupt a CPU bound job to
> give cycles to other applications.
They may give cycles to other jobs, based on the usual timeslicing,
but that is no excuse to chew up complete timeslices doing nothing.
In fact Windows gives more timeslices to forgound programs so if this
is a foreground task it will waste more CPU cycles than is given to
background programs.
A good multi-tasking system (such as some that I have used) will
actually detect such waste-time loops and will give it less cycles.
This is useful when multi-tasking DOS programs where clueless
programmers seemed to never consider that other programs could use the
CPU. Loops checking for keyhit() while using 100% CPU were typical.
Windows running 2 or 3 of these would be brought to its knees while a
_good_ multi-tasker intercepted those and/or 'niced' them to a lower
priority.
DOS did have a 'despatch' function which truncated the timeslice.
Adding this in the 'sleep' loop would minimise the CPU access while
having no effect on the program itself, yet I found few DOS
programmers who even knew it existed, let alone why they would care.
| |
| Michael Wojcik 2004-09-12, 3:55 pm |
|
In article <5u3rj0dugnsgpuapracs2ciure4pt0m8r2@4ax.com>, Robert Wagner <robert@wagner.net.yourmammaharvests> writes:
>
> Sleep is not a *standard* Cobol function; is it a standard C function.
It's neither. "sleep" (lowercase s) is a standard POSIX / SUS function
(see IEEE Std 1003.1-2001 and subsequent editions, Open Group Base
Specifications Issue 6, etc). "Sleep" (capital S) is a Windows function
(with different syntax), not endorsed by any standards group I'm aware
of. There may of course be other implementations of "sleep" functions
in other domains.
C does not define a "sleep" function or other reserved identifier. See
ISO 9899:1990 and subsequent editions.
The POSIX sleep need not be implemented in C, of course.
--
Michael Wojcik michael.wojcik@microfocus.com
However, we maintain that our mission is more than creating high-tech
amusement--rather, we must endeavor to provide high-tech, high-touch
entertainment with an emphasis on enkindling human warmth.
-- "The Ultimate in Entertainment", from the president of video game
producer Namco
| |
| William Cai 2004-09-12, 3:55 pm |
| I am using Microfocus COBOL suite. Thanks.
-William
| |
| William Cai 2004-09-12, 3:55 pm |
| Hi, list
I am looking for the solution. Could anybody please tell me how to code
instead of discussing if sleep is a Cobol standard function? Though
your dicussion also helps me. :P
Repeat my question.
I wanna develop a COBOL program. The program will sleep several seconds
according to user's input.
I have no instructor. So you are all my instructors. Many thanks for
your help.
William
| |
| William Cai 2004-09-12, 3:55 pm |
| Update my question:
I list my program as below. But whatever I input, the program will sleep for
a very long time. I am sure not if the program hangs. Anyone can help? Thank
you.
IDENTIFICATION DIVISION.
PROGRAM-ID. EXAM1.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 SLEEP-SEC PIC 9.
PROCEDURE DIVISION.
S. DISPLAY 'THIS IS COBOL'.
DISPLAY 'PLEASE INPUT THE SECONDS FOR SLEEP'.
ACCEPT SLEEP-SEC.
DISPLAY 'WILL SLEEP ', SLEEP-SEC, ' SECONDS'.
CALL "sleep" USING SLEEP-SEC;
STOP RUN.
"William Cai" <wenliang_cai@yahoo.com.cn> wrote in message
news:chjjss$t76$1@mail.cn99.com...
Hi, folks
Anybody can tell me how to let a COBOL program sleep 5 seconds? I am new to
COBOL. Sorry for the stupid question. :)
-William
| |
| William Cai 2004-09-13, 3:55 am |
| thanks a lot. :)
-William
| |
| JerryMouse 2004-09-13, 3:55 pm |
| Richard wrote:
> "JJ" <jj@nospam.com> wrote
>
>
> This is _not_ a 'sleep' function. It is a 'use_all_the
> CPU_time_available' function.
>
> On multi-user or multi-tasking machines this is not being friendly. On
> poor multi-taskers such as Windows it will affect the running of the
> whole system.
Ah, not exactly. Starting with Win98 (and all the NT variants, 2K, XP),
Windows has preemptive multi-tasking and will interrupt a CPU bound job to
give cycles to other applications.
| |
|
| > This is _not_ a 'sleep' function. It is a 'use_all_the
> CPU_time_available' function.
Hence the very first line of my post (perhaps you didn't read it):
"Although it is not very efficient from a CPU perspective"
"Richard" <riplin@Azonic.co.nz> wrote in message
news:217e491a.0409071103.7bbbaeea@posting.google.com...
> "JJ" <jj@nospam.com> wrote
>
>
> This is _not_ a 'sleep' function. It is a 'use_all_the
> CPU_time_available' function.
>
> On multi-user or multi-tasking machines this is not being friendly. On
> poor multi-taskers such as Windows it will affect the running of the
> whole system.
| |
| Robert Wagner 2004-09-13, 3:55 pm |
| On 7 Sep 2004 19:36:41 -0700, riplin@Azonic.co.nz (Richard) wrote:
>In fact Windows gives more timeslices to forgound programs so if this
>is a foreground task it will waste more CPU cycles than is given to
>background programs.
>
>A good multi-tasking system (such as some that I have used) will
>actually detect such waste-time loops and will give it less cycles.
>This is useful when multi-tasking DOS programs where clueless
>programmers seemed to never consider that other programs could use the
>CPU. Loops checking for keyhit() while using 100% CPU were typical.
>Windows running 2 or 3 of these would be brought to its knees while a
>_good_ multi-tasker intercepted those and/or 'niced' them to a lower
>priority.
I anticipated that in my text editor by providing a multi-tasking
option. If off, it runs in a loop looking for a keystroke, mouse
event, possible garbage collection, etc. If on, it runs one of each
test, then Yields the rest of its timeslice.
On every Windows since 95, it has not hogged CPU time whether the
option was on or off. When 'in focus' and idling, it uses less than 1%
of CPU time.
| |
| Jack Sleight 2004-09-13, 8:55 pm |
| For those of you lurking and looking for an IBM mainframe solution,
the following from a sister forum may help:
http://groups.google.com/groups?q=i...com.com&rnum=11
It was authored by Bill Klein, a regular contributor here.
"William Cai" <caiwenliang@gmail.com> wrote in message news:<ci3bqo$11l@odak26.prod.google.com>...
> thanks a lot. :)
>
> -William
| |
| Richard 2004-09-15, 3:55 am |
| "William Cai" <caiwenliang@gmail.com> wrote
> I am looking for the solution. Could anybody please tell me how to code
> instead of discussing if sleep is a Cobol standard function? Though
> your dicussion also helps me. :P
If sleep was a standard Cobol function then it would be easy to tell
you exactly how to do it. It isn't.
It isn't even a standard C function, though it may be in a C library.
It may be possible to call a C library depending on your compiler and
the system you are running on. (yes I know it is MF now, but not the
OS).
> Repeat my question.
> I wanna develop a COBOL program. The program will sleep several seconds
> according to user's input.
You have been told this. The actual answer is that 'sleep' requires a
parameter that is S9(9) COMP-5 and that this be passed BY VALUE.
01 Sleep-Seconds PIC S9(9) COMP-5.
CALL "sleep" USING BY VALUE Sleep-Seconds
To get the value into that use a single digit input:
01 Sleep-Input PIC 9.
DISPLAY "How many seconds"
ACCEPT Sleep-Input
MOVE Sleep-Input TO Sleep-Seconds
CALL ...
| |
| dr_te_z 2004-09-15, 8:02 am |
| code: SPECIAL-NAMES.
Call-convention 3 is 32bitPC.
01 WRK.
03 SleepMiliSec Pic 9(8) comp-5.
03 Nsleep.
05 NsleepS pic 9(8) comp-5.
05 NsleepN pic 9(8) comp-5.
*
03 WS-Seconden pic 9(2)v9(3).
03 WS-SecGroup redefines
WS-Seconden.
05 WS-WholeSeconds pic 9(2).
05 WS-MiliS-remain pic 9(3).
03 CBLrc PIC 9(2) comp-x.
......
Evaluate true
*
when C8-OS2-16bit
Move ALG-os-MiliSec to SleepMiliSec
Call "__DosSleep" using by value SleepMiliSec
End-call
*
when C8-OS2-32bit
Move ALG-os-MiliSec to SleepMiliSec
Call 32bitPC "DosSleep" using by value SleepMiliSec
returning CBLRc
End-call
*
when C8-Win-32bit
Move ALG-os-MiliSec to SleepMiliSec
Call 32bitPC "Sleep" using by value SleepMiliSec
returning CBLRc
End-call
*
when C8-unix32Bit
Move ALG-os-Seconden to WS-Seconden
Move WS-WholeSeconds to NsleepS
Multiply WS-MiliS-remain
by 1000000 giving NsleepN
Call "nsleep" using Nsleep
returning CBLRc
End-call
*
end-evaluate.
This code works using micro focus COBOL on OS/2, windows32 and unix/linux. | |
| William Cai 2004-09-15, 3:55 pm |
| Hi, list
I am looking for the solution. Could anybody please tell me how to code
instead of discussing if sleep is a Cobol standard function? Though
your dicussion also helps me. :P
Repeat my question.
I wanna develop a COBOL program. The program will sleep several seconds
according to user's input.
I have no instructor. So you are all my instructors. Many thanks for
your help.
William
| |
| JerryMouse 2004-09-16, 8:55 am |
| William Cai wrote:
> Hi, list
>
> I am looking for the solution. Could anybody please tell me how to
> code instead of discussing if sleep is a Cobol standard function?
> Though your dicussion also helps me. :P
>
> Repeat my question.
> I wanna develop a COBOL program. The program will sleep several
> seconds according to user's input.
>
> I have no instructor. So you are all my instructors. Many thanks for
> your help.
1. Get the time of day.
2. Compute end-time by adding five seconds to the current time.
3. Loop checking the time of day until end-time is reached, viz:
PERFORM UNTIL SECONDS-NOW > END-TIME
ACCEPT ...
COMPUTE SECONDS-NOW = ...
END-PERFORM
| |
| William Cai 2004-09-16, 3:56 pm |
| I am using Microfocus COBOL suite. Thanks.
-William
|
|
|
|
|