【发布时间】:2012-10-24 13:04:23
【问题描述】:
在 Ubuntu 上 - 内核 2.6.32.2
如何在不借助任何库的情况下直接从用户代码调用已有的系统调用? 我在书籍和互联网上阅读以解决此问题,然后编写以下代码但仍然出现错误。请帮忙
想知道当前进程的进程id
#include <stdio.h>
#include<linux/unistd.h> // for __NR_getpid
_syscall0(int, getpid)
int main() {
printf("Current Process ID : %d\n",getpid());
return 0;
}
编译时出错:
root@Omkant:~/os# gcc -Wall getpid.c -o getpid
getpid.c:5:16: error: expected declaration specifiers or ‘...’ before ‘getpid’
getpid.c:5:1: warning: data definition has no type or storage class
getpid.c:5:1: warning: type defaults to ‘int’ in declaration of ‘_syscall0’
getpid.c: In function ‘main’:
getpid.c:8:2: warning: implicit declaration of function ‘getpid’
代码有什么问题?请帮忙...
【问题讨论】:
-
"但仍然出现错误" -- 编译时间?运行?为什么要隐藏这些重要信息?
-
对不起....现在是编译时间...
-
请使用实际的错误消息(完整,逐字)编辑您的帖子。 “一个错误”对任何人都没有帮助。
-
如果您想了解如何编写它们并从头开始使用,请尝试此操作。stackoverflow.com/questions/12469836/…
-
@askmish : 谢谢..但我知道如何编写我们自己的系统调用和调用过程..但我想在没有库函数帮助的情况下调用现有的系统调用
标签: c posix system-calls