I think I figured it out. Times() doesn't have enough precision. Ticks-per-second (i.e. sysconf(3)) on z/OS is 100. So 1 tick would be 0.01 CPU second.
Which means all my tests where getrusage was < .01, times() wasn't even at its first tick. I can confirm this by doing a lot of calls. I see the first tick just at getrusage goes over .01: getrusage cpu seconds: .007198 User ticks = 0000000000 System = 0000000000 getrusage cpu seconds: .017204 User ticks = 0000000000 System = 0000000001 And, I just realized I should be able to call clock_gettime() with a value that gives the CPU time. I already have working COBOL code for CLOCK_REALTIME, so this will be better. -----Original Message----- From: IBM Mainframe Discussion List <[email protected]> On Behalf Of Schmitt, Michael Sent: Friday, September 27, 2024 1:31 PM To: [email protected] Subject: Why does times() always return zeros? I'm using z/OS to test a program that will eventually run on Linux. The purpose of the program is to return the total CPU time (in seconds with micro-second precision) consumed by the current process, so far. If I were coding this in HLASM it would be: timeused storadr=cpu_time_binary_w, get cpu time x linkage=SYSTEM, in microseconds x cpu=MIC (SSSSS.thmiju) I'm coding this in COBOL, for reasons, using the cool fact that you can make calls to the C library. If I make a call to getrusage() then I get back some time, but it is much less than the actual time. For example, if I run it at the end of a step that uses about 11.5 CPU seconds, I get: Assembler CPU seconds: 11.513959 Linux CPU seconds: .019033 I see in our site's job resource usage displays that it appears that when I do the getrusage() call, it is running in the OMVS side. So I think the getrusage() is only reporting the CPU time used by that side, not anything going on in MVS. But if I make a call to times(), which returns a tms structure: 05 tms_w. 10 tms_utime pic s9(9) comp-5. *> user 10 tms_stime pic s9(9) comp-5. *> system 10 tms_cutime pic s9(9) comp-5. *> child user 10 tms_cstime pic s9(9) comp-5. *> child system I always get zeros. I get zeros even if I make a call to getrusage(), then the times() call, then getrusage(), and then times(): getrusage cpu seconds: .001980 User ticks = 0000000000 System = 0000000000 Child User ticks = 0000000000 Child System = 0000000000 getrusage cpu seconds: .002111 User ticks = 0000000000 System = 0000000000 Child User ticks = 0000000000 Child System = 0000000000 The fact the getrusage result is increasing implies that the OMVS process was still running, and it is the total time since it started. So I'd think the second times() call would return SOMETHING. This is on z/OS 2.5. times() is documented at https://www.ibm.com/docs/en/zos/2.5.0?topic=functions-times-get-process-child-process-times ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN ---------------------------------------------------------------------- For IBM-MAIN subscribe / signoff / archive access instructions, send email to [email protected] with the message: INFO IBM-MAIN
