标签:
在网上查询getpid函数的C语言代码以及其嵌入式汇编语句
C语言代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
pid_t tt;
tt = getpid();
printf("%u\n", tt);
return 0;
}
嵌入式汇编语句:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
pid_t tt;
asm volatile(
"mov $0x14, %%eax\n\t"
"int $0x80\n\t"
"mov %%eax, %0\n\t"
:"=m" (tt)
);
printf("%u\n", tt);
return 0;
}
再用gcc将该函数代码进行编译。通过输入指令./getpid即可得出目前进程号为:29895
5.修改getpid.c,改为嵌入式汇编语句,保存并退出后,使用以下命令gcc getpid -o getpid.c -m32编译
6.使用以下命令 ./getpid 运行得到目前的进程号为11926
1.API(xyz)
2.中断向量(system_call)
3.中断服务程序(sys_xyz)
1.系统调用号放在eax中。
2.系统调用的参数,按照顺序分别放在ebx、ecx、edx、esi、edi和ebp中
3.返回值使用eax传递
作者: 王雪铖
原创作品转载请注明出处
《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000
标签:
原文地址:http://www.cnblogs.com/20135105wangxc/p/5298136.html