在 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’
代码中有什么问题?请帮忙...