Linux 中的量子力学

 Linux中的量子力学文件 

1、uuid

# cat /proc/sys/kernel/random/uuid 
afe529fe-1d73-4b72-90f2-34dbb70492f

每次查看该文件,都会生成一个不同的uuid。

于是检测每次是什么进程去修改这个文件的内容,然而更神奇的事情发生了。

假如我用echo的方式查看,那么就是echo命令修改的这个文件,如果是cat命令,那么就是cat的命令修改的这个文件。

但是这个文件具体的实现方式我还是很不理解,希望有前辈做出解答。

像这样的文件在/proc/sys/kernel/random/目录下还有好多,每个都可以在每次查看的时候生成不同的内容。很是神奇

# ls /proc/sys/kernel/random/
boot_id        read_wakeup_threshold    write_wakeup_threshold
entropy_avail  urandom_min_reseed_secs
poolsize       uuid

2020年3月10日16:28:43

链接:https://exp.newsmth.net/topic/cfa808e7338c78375a1e1adff206a676

      前段时间在水木社区提问过该问题,有两位大神做出了如下回答

回答1:  rtfs,不是很明白,下去我再百度查查

回答2:为random的源码

drivers/char/random.c

/*

* This function is used to return both the bootid UUID, and random

* UUID. The difference is in whether table->data is NULL; if it is,

* then a new UUID is generated and returned to the user.

*

* If the user accesses this via the proc interface, the UUID will be

* returned as an ASCII string in the standard UUID format; if via the

* sysctl system call, as 16 bytes of binary data.

*/

static int proc_do_uuid(struct ctl_table *table, int write,

void __user *buffer, size_t *lenp, loff_t *ppos)

{

struct ctl_table fake_table;

unsigned char buf[64], tmp_uuid[16], *uuid;

 

uuid = table->data;

if (!uuid) {

uuid = tmp_uuid;

generate_random_uuid(uuid);

} else {

static DEFINE_SPINLOCK(bootid_spinlock);

 

spin_lock(&bootid_spinlock);

if (!uuid[8])

generate_random_uuid(uuid);

spin_unlock(&bootid_spinlock);

}


sprintf(buf, "%pU", uuid);


fake_table.data = buf;

fake_table.maxlen = sizeof(buf);


return proc_dostring(&fake_table, write, buffer, lenp, ppos);

}
原文地址:https://www.cnblogs.com/despotic/p/12378568.html