Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a unique id from a unix-like system

Tags:

I want to get from any Unix-like system (if this is possible) a unique id that will be persistent every time my application runs in the same machine. If it is possible, I want to get the same id from Linux or FreeBSD or Solaris, etc... I don't want to generate a new id for each machine, but get an already existent id, and I prefer this id to come from the operating system and I don't prefer to use something like the MAC address.

If there is no other option available, I can use MAC in combination with something else, for example the id can be the md5 hash of the combination of the MAC address and something else.

I would like to listen to your suggestions.

If it is useful, my application is written in C/C++.

The aim of all this is to prevent a user to run my application for two or more times. I want to run just once.

like image 879
Blue Avatar asked Nov 30 '08 15:11

Blue


People also ask

How do I find unique ID in Linux?

Most of the Linux/Unix system supports the command line utility tool uuidgen to generate the UUID. If the package is unavailable install using apt install uuid-runtime command. Uuidgen can generate random-based, time-based and hash-based UUIDs. Random based UUIDs is sufficient in most cases.

How do I find unique system ID?

To generate a mostly unique machine id, you can get a few serial numbers from various pieces of hardware on the system. Most processors will have a CPU serial number, the hard disks each have a number, and each network card will have a unique MAC address. You can get these and build a fingerprint for the machine.

What is unique ID in Linux?

UUID is a unique identifier used in partitions to uniquely identify partitions in Linux operating systems. UUID is a property of the disk partition itself. So, if you install the hard drive containing the partitions on another Linux computer, the partitions will have the same UUID as before. So, that's a good thing.

Which of the following is the unique identifier for a process?

An item's unique item identifier (UII) refers to its entry value in a database. UIIs are usually machine-readable and help contractors track each item digitally through all stages of its lifecycle.


1 Answers

How about the UUID of the root filesystem? You can get the root filesystem device from /etc/fstab, either by manually parsing the file or by using getfsent (3) or getfsfile (3). Once you have the device, you can get the UUID by either checking the links in /dev/disk/by-uuid or from the blkid command.

like image 164
Jason Day Avatar answered Sep 27 '22 18:09

Jason Day