gpt4 book ai didi

Linux 操作系统中 main() 的计数器

转载 作者:行者123 更新时间:2023-11-30 19:04:34 25 4
gpt4 key购买 nike

我想在Linux中实现一个计数器来记录多少次main() 可以被任何进程调用。

当我将这个计数器作为一个进程启动时,从那时起它会告诉我 main() 不是由我的程序调用而是在整个操作系统系统中调用了多少次

示例:我将其作为守护进程启动,然后创建一个简单的代码

#include <stdio.h>

int main(){
//some code
return 0;
}

现在 main 被调用,因此计数器将增加 1。

谁能解释一下这是怎么做到的?

谢谢

最佳答案

您可能想看看:Proc connector and socket filters

The Proc Connector and Socket Filters Posted on February 9, 2011 by scott

The proc connector is one of those interesting kernel features that most people rarely come across, and even more rarely find documentation on. Likewise the socket filter. This is a shame, because they’re both really quite useful interfaces that might serve a variety of purposes if they were better documented.

The proc connector allows you to receive notification of process events such fork and exec calls, as well as changes to a process’s uid, gid or sid (session id). These are provided through a socket-based interface by reading instances of struct proc_event defined in the kernel header....

关于Linux 操作系统中 main() 的计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51781113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com