Mon*_*lal 2 c linux operating-system posix fork
我想编写一个简单的“C”程序来查找操作系统启动后的系统调用次数。我正在跟踪其他系统调用,例如 fork() 或 getpid() 并基本上复制它们的大部分内容。我不确定应该在哪里/何时增加计数器?有什么例子吗?
\n\n在 kernel/syscall.c 中定义计数器并相应地增加它是一个好主意吗?
\n\nvoid\nsyscall(void)\n{\n int num;\n counter++; //mona\n num = proc->tf->eax;\n if(num > 0 && num < NELEM(syscalls) && syscalls[num] != NULL) {\n proc->tf->eax = syscalls[num]();\n } else {\n cprintf("%d %s: unknown sys call %d\\n",\n proc->pid, proc->name, num);\n proc->tf->eax = -1;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n另外,这是我迄今为止在 kernel/sysproc.c 中用于简单系统调用的代码:
\n\nsys_getsyscallinfo(void)\n{\n\n return counter; //mona\n}\nRun Code Online (Sandbox Code Playgroud)\n\n但是我收到这个错误:
\n\nkernel/sysproc.c: In function \xe2\x80\x98sys_getsyscallinfo\xe2\x80\x99:\nkernel/sysproc.c:48: error: \xe2\x80\x98counter\xe2\x80\x99 undeclared (first use in this function)\nkernel/sysproc.c:48: error: (Each undeclared identifier is reported only once\nkernel/sysproc.c:48: error: for each function it appears in.)\nmake: *** [kernel/sysproc.o] Error 1\nRun Code Online (Sandbox Code Playgroud)\n
我将计数器变量定义为 extern int ,kernel/defs.h并在系统调用定义中将其用作返回值,kernel/sysproc.c并在所有陷阱处理均在 中完成的地方增加了它kernel/syscall.c。我希望它有帮助。