相关疑难解决方法(0)

132
推荐指数
4
解决办法
10万
查看次数

直接从用户程序访问系统调用

在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)

代码中的问题是什么?请帮忙...

c posix system-calls

9
推荐指数
1
解决办法
9409
查看次数

标签 统计

abi ×1

assembly ×1

c ×1

linux ×1

posix ×1

system-calls ×1

unix ×1

x86-64 ×1