AT&T ASSEMBLY FOR LINUX AND MAC (SYS_FORK)

本文详细探讨了C语言中fork()函数的工作原理,通过对比不同平台的实现方式,展示了如何在C语言环境下创建子进程。从源代码层面解析了fork()函数在AT&T for Linux平台的具体实现,并通过示例代码演示了其运行流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Fork() in C: (sys_fork.c)

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(void)
{
    fork();
    printf("Hello Landpack\n");
    return 0;
}

Fork() in AT&T for Linux:(sys_fork.s)

.section .rodata
msg:    .ascii "Hello Landpack\n"
    len = .-msg

.section .bass

.section .text
.globl _start
_start:
    movl    $2,%eax     # sys_fork number (2)
    int     $0x80

# As we know,if we fork() in C
# we will run the double process
# They almost have the same code and data

    movl    $4,%eax     # sys_write number (4)
    movl    $1,%ebx     # STDOUT_FILENO == (1)
    movl    $msg,%ecx   # The head address of msg
    movl    $len,%edx   # The offset of addr
    int     $0x80

    movl    $1,%eax
    movl    $0,%ebx
    int     $0x80

 

转载于:https://www.cnblogs.com/landpack/p/4483242.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值