从类Unix系统获取唯一ID [英] Getting a unique id from a unix-like system

查看:175
本文介绍了从类Unix系统获取唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从任何类似Unix的系统(如果可能的话)中获得一个唯一的ID,该ID在我的应用程序每次在同一台机器上运行时都将保持不变.如果可能的话,我想从Linux或FreeBSD或Solaris等系统中获取相同的ID.我不想为每台计算机生成一个新的ID,但希望获取一个已经存在的ID,因此我更希望使用该ID来代替来自操作系统,我不喜欢使用MAC地址之类的东西.

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.

如果没有其他可用选项,我可以将MAC与其他东西结合使用,例如id可以是MAC地址和其他东西组合的md5哈希值.

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.

我想听听您的建议.

如果有用,我的应用程序是用C/C ++编写的.

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.

推荐答案

根文件系统的UUID如何?您可以通过手动解析文件或使用getfsent (3)getfsfile (3)/etc/fstab获取根文件系统设备.拥有设备后,您可以通过检查/dev/disk/by-uuid中的链接或通过blkid命令来获取UUID.

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.

这篇关于从类Unix系统获取唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆