MCPcopy Create free account
hub / github.com/apache/cloudberry / InitProcessGlobals

Function InitProcessGlobals

src/backend/postmaster/postmaster.c:3157–3185  ·  view source on GitHub ↗

* InitProcessGlobals -- set MyProcPid, MyStartTime[stamp], random seeds * * Called early in the postmaster and every backend. */

Source from the content-addressed store, hash-verified

3155 * Called early in the postmaster and every backend.
3156 */
3157void
3158InitProcessGlobals(void)
3159{
3160 unsigned int rseed;
3161
3162 MyProcPid = getpid();
3163 MyStartTimestamp = GetCurrentTimestamp();
3164 MyStartTime = timestamptz_to_time_t(MyStartTimestamp);
3165
3166 /*
3167 * Set a different seed for random() in every process. We want something
3168 * unpredictable, so if possible, use high-quality random bits for the
3169 * seed. Otherwise, fall back to a seed based on timestamp and PID.
3170 */
3171 if (!pg_strong_random(&rseed, sizeof(rseed)))
3172 {
3173 /*
3174 * Since PIDs and timestamps tend to change more frequently in their
3175 * least significant bits, shift the timestamp left to allow a larger
3176 * total number of seeds in a given time period. Since that would
3177 * leave only 20 bits of the timestamp that cycle every ~1 second,
3178 * also mix in some higher bits.
3179 */
3180 rseed = ((uint64) MyProcPid) ^
3181 ((uint64) MyStartTimestamp << 12) ^
3182 ((uint64) MyStartTimestamp >> 20);
3183 }
3184 srandom(rseed);
3185}
3186
3187
3188/*

Callers 3

InitPostmasterChildFunction · 0.85
InitStandaloneProcessFunction · 0.85
PostmasterMainFunction · 0.85

Calls 4

GetCurrentTimestampFunction · 0.85
pg_strong_randomFunction · 0.85
srandomFunction · 0.85
timestamptz_to_time_tFunction · 0.50

Tested by

no test coverage detected