Cloud
Cloud

Reputation: 19331

Portable way to acquire per-boot random seed in C on Linux

Question

Is there a way for two separate processes, built using on Linux, to acquire some sort of per-boot pseudo-random seed/value from a global location?


Background

In short, I have two simple processes that would like to talk to each other via a randomly-named, Unix domain socket, like so:

The idea is to randomize the file name both processes will use at boot, but they need to know some way to both determine the common path without talking to each other in advance.


Work so far

I've tried using the starttime of the init process, by effectively doing the following command in c:

cat /proc/1/stat | cut -d ' ' -f22

However, this value is typically the same from boot-to-boot, so it's not random enough. I was thinking of maybe writing a simple Linux kernel module that would provide this value, but that seems like overkill.


Question (redux)

Is there some source of random data which remains the same for a single boot, but not across subsequent boots, which I could read via a non-root process in Linux?

Upvotes: 1

Views: 191

Answers (1)

user149341
user149341

Reputation:

/proc/sys/kernel/random/boot_id contains a random UUID generated at boot.

Upvotes: 5

Related Questions