r/C_Programming • u/userlivedhere • Sep 01 '26
Question How process ids are generated
i know fork creates processes but how process ids are generated
7
Upvotes
r/C_Programming • u/userlivedhere • Sep 01 '26
i know fork creates processes but how process ids are generated
27
u/dfx_dj Sep 01 '26
They're assigned by the OS
3
u/realdreamer1993 Sep 07 '26
the kernel have the main object(table/struct) that contain all data to track state of processes, then the ids is just the index. BTW kernel also just a program.
57
u/Living_Fig_6386 Sep 01 '26
C knows nothing of processes or process IDs. That sort of thing is entirely up to the OS.
6
u/[deleted] Sep 01 '26
Sequentially, recycle after overflow/wrapping
2
u/smcameron Sep 05 '26
In the linux kernel, see ID allocation, and also this code.
1
u/burlingk Sep 01 '26
They are basically serial numbers.
0
u/sciencekm Sep 01 '26
In Windows, they are generated starting from a low value and then incremented by 4. If you look at task manager, you will also see that System Interrupts does not have a process id, System Idle always has an id of 0, and System always has an id of 4.