您的位置:首页 > 运维架构 > Linux

linux 系统调用示例

2013-03-01 16:02 225 查看
#include <stdio.h>
#include <errno.h>

#define __NR_mysyscall 341

#define _syscall0(type, name) \
type name(void) \
{ \
long __res; \
__asm__ __volatile__("int $0x80":"=a"(__res) :"a"(__NR_##name)); \
if (__res >= 0) \
return (type) __res; \
errno = -__res; \
return -1; \
}

_syscall0(int, mysyscall)

int main(int argc, char* argv[])
{
int res;

res = mysyscall();
if (res < 0)
printf("call mysyscall res=%d, strerror(%d)=%s\n", res, errno, strerror(errno));
else
printf("call mysyscall ok res=%d\n", res);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: