以下链接解释了UNIX(BSD风格)和Linux的x86-32系统调用约定:
但是UNIX和Linux上的x86-64系统调用约定是什么?
在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;
}
Run Code Online (Sandbox Code Playgroud)
编译时出错:
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’
Run Code Online (Sandbox Code Playgroud)
代码中的问题是什么?请帮忙...