首页 > 编程知识 正文

linux进阶书籍,Linux进阶命令

时间:2023-05-06 12:18:57 阅读:274412 作者:1276

1. 概念

syscall()是一个小的库函数,它调用系统调用,该系统调用的汇编语言接口具有指定的带指定参数的数字。

syscall()在进行系统调用之前保存CPU寄存器,从系统调用返回时恢复寄存器,如果发生错误,将系统调用返回的任何错误代码存储在errno。

2. 函数定义 #define _GNU_SOURCE /* See feature_test_macros(7) */#include <unistd.h>#include <sys/syscall.h> /* For SYS_xxx definitions */int syscall(int number, ...); 3. 返回值

成功返回0,失败返回-1。

4. 参数

syscall() 执行一个系统调用,根据指定的参数number和所有系统调用的汇编语言接口来确定调用哪个系统调用。
系统调用所使用的符号常量可以在头文件<sys/syscll.h>里面找到。

5. 示例 #define _GNU_SOURCE#include <unistd.h>#include <sys/syscall.h>#include <sys/types.h>#include <signal.h>#include <stdio.h>int main(int argc, char *argv[]){ pid_t tid; tid = syscall(SYS_gettid); printf("tid:%dn",tid); tid = syscall(SYS_tgkill, getpid(), tid, SIGHUP); printf("tid:%dn",tid); return 0;}

编译运行:

[root@192 syscall]# gcc syscall.c -o syscall[root@192 syscall]# lssyscall syscall.c[root@192 syscall]# ./syscall tid:1811挂起[root@192 syscall]#

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。