The correct behavior is for endtime
in the child to be a small, close-to-zero value if you use CLOCK_PROCESS_CPUTIME_ID
, since fork
sets it to zero for the child. For the parent, it will be a value slightly larger than, but almost identical to starttime
.
This is well-documented in the fork(2)
manpage, and it is what makes sense too -- you create a new process. The new process has, of course, not consumed any CPU time. It's a newborn process, after all! The parent, on the other hand, has already consumed noticeable CPU and continues doing so, there is no good reason why its counter should be reset to zero (that would be a lie).
Other clocks like CLOCK_REALTIME
or CLOCK_MONOTONIC
will not be affected (the former can independently of you forking be modified by a privilegued user, but the latter cannot).
That, too, is according to what common sense tells you. They're global timers, if forking a new process (which happens nearly all the time) was interfering with them, it would be a desaster.