pid start time and new display field in proc pid stat [ race in task->start_boottime , start_time]

Valdis Kl=?utf-8?Q?=c4=93?=tnieks valdis.kletnieks at vt.edu
Fri Apr 2 23:21:40 EDT 2021


On Thu, 01 Apr 2021 20:20:04 +0530, Navin P said:

> After printing the task->start_boottime as 53rd field, i found
> multiple process containing same value due to a race. The race exists
> for p->start_time as well.

Well, yeah.  There's no existing reason that the kernel shouldn't be able to
spawn processes on two CPUs in parallel (and initialize the start_time field to
the same value along the way).  There should be as little synchronizing locking
as possible, and if you need to do something that requires locking, you should
probably piggyback it on top of a code section that already has the appropriate
locks in place.

> What are the other ways  that can be used to fix this problem ?

Is there a particular reason why your code *needs* to have different unique
values for the start_time and start_boottime fields?  If your code needs
something unique per-process, the tuple (start_time, PID) *will* be unique
system-wide.  Or just PID.

In other words, what problem are you trying to solve by making the start_time
unique?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20210402/b6142864/attachment.sig>


More information about the Kernelnewbies mailing list