Use the same system call using the Library function API and the embed assembly code in C code two ways

Source: Internet
Author: User

Zhu Hengzhi + "Linux kernel analysis" MOOC course http://mooc.study.163.com/course/USTC-1000029000 "

Use the same system call using the Library function API and the embed assembly code in C code two ways

List of system calls see HTTP://CODELAB.SHIYANLOU.COM/XREF/LINUX-3.18.6/ARCH/X86/SYSCALLS/SYSCALL_32.TBL

I have chosen number 20th:

Use the Library function API to display the ID of the process on the screen:

Use the C language to embed the assembly code:

Code:

#include <unistd.h>

#include <stdio.h>

int main ()

{

pid_t pid; PID = Getpid ();

ASM volatile (

"Mov $0x14,%%eax\n\t"

"Int $0x80\n\t"

"Mov%%eax,%0\n\t"

< Span class= "Hljs-keyword" >&NBSP;: "=m" (PID));

< Span class= "Hljs-keyword" > printf ( "pid =%d \ n", pid);

< Span class= "Hljs-keyword" > return 0;

< Span class= "Hljs-keyword" > }

Use the same system call using the Library function API and the embed assembly code in C code two ways

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.