mac os x显示进程产生的Mach与BSD系统调用的数量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了mac os x显示进程产生的Mach与BSD系统调用的数量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1693字,纯文字阅读大概需要3分钟。
内容图文
// syscalls_test.c
#include <stdio.h>
#include <fcntl.h>>
#include <unistd.h>
#include <mach/mach.h>
int
main()
{
int i, fd;
mach_port_t p;
kern_return_t kr;
setbuf(stdout, NULL);
printf("My pid is %d\n", getpid());
printf("Note the number of Mach and Unix system calls, and press <enter>");
(void)getchar();
// At this point, we will have some base numbers of Mach and Unix
// system calls made so far, say, M and U, respectively
for (i = 0; i < 100; i++) { // 100 iterations
// +1 Unix system call per iteration
fd = open("/dev/null", O_RDONLY);
// +1 Unix system call per iteration
close(fd);
// +1 Mach system call per iteration
kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &p);
// +1 Mach system call per iteration
kr = mach_port_deallocate(mach_task_self(), p);
}
// +1 Unix system call
printf("Note the number of Mach and Unix system calls again...\n"
"Now sleeping for 60 seconds...");
// sleep(3) is implemented using nanosleep, which will call
// clock_get_time() and clock_sleep_trap() -- this is +2 Mach system calls
(int)sleep(60);
// Mach system calls = M + 2 * 100 + 2 (that is, 202 more calls)
// Unix system calls = U + 2 * 100 + 1 (that is, 201 more calls)
return 0;
}
用工具:https://blog.51cto.com/haidragon/2417758
haidragondeMacBook-Pro:7-22 haidragon$ gcc -Wall -o syscalls_test syscalls_test.c
syscalls_test.c:4:19: warning: extra tokens at end of #include directive [-Wextra-tokens]
#include <fcntl.h>>
^
//
syscalls_test.c:46:5: warning: expression result unused [-Wunused-value]
(int)sleep(60);
^ ~~~~~~~~~
2 warnings generated.
haidragondeMacBook-Pro:7-22 haidragon$ ./syscalls_test
My pid is 2128
Note the number of Mach and Unix system calls, and press <enter>
内容总结
以上是互联网集市为您收集整理的mac os x显示进程产生的Mach与BSD系统调用的数量全部内容,希望文章能够帮你解决mac os x显示进程产生的Mach与BSD系统调用的数量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。