linux下的excel

今天调试ptrace的一个用例,里面用到了excel这个函数:

#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reg.h>   /* For constants  ORIG_RAX etc */
#include <stdio.h>
int main()
{   
	pid_t child;
    long orig_rax;
    child = fork();
    if(child == 0) 
    {
        ptrace(PTRACE_TRACEME, 0, NULL, NULL);
        printf("Try to call: execl\n");
        execl("/bin/ls", "ls", NULL);
        printf("child exit\n");
    }
    else 
    {
        wait(NULL);
        orig_rax = ptrace(PTRACE_PEEKUSER,
                          child, 8 * ORIG_RAX,
                          NULL);
        printf("The child made a "
               "system call %ld\n", orig_rax);
        ptrace(PTRACE_CONT, child, NULL, NULL);
        printf("Try to call:ptrace\n");
    }
    return 0;
}

上面的代码来自:https://blog.csdn.net/litost000/article/details/82813641

运行的时候发现,child exit 永远打印不出来,尝试了各种办法,因为之前从来没用过excel函数,对其不了解,所以也没向它考虑,后来通过最笨的方式进行尝试,验证出就是excel的问题,然后一查,果然。。。。。

excel的一个特点:

当进程调用一种exec函数时,该进程完全由新程序代换,而新程序则从其main函数开始执行。因为调用exec并不创建新进程,所以前后的进程ID并未改变。exec只是用另一个新程序替换了当前进程的正文、数据、堆和栈段。

用另一个新程序替换了当前进程的正文、数据、堆和栈段。

当前进程的正文都被替换了,那么execl后的语句,即便execl退出了,都不会被执行
上面的话来自:https://blog.csdn.net/bao_bei/article/details/48287945

但是对其参数也不了解,也就顺便查了一下:

Linux下头文件

#include <unistd.h>

函数定义

int execl(const char *path, const char *arg, ...)

实例1


/*
 * execl函数使用实例1
 *功能:执行/bin/ls -al /etc/passwd
 * */
#include <unistd.h>

int main(void)
{
    //执行/bin目录下的ls
    //第一个参数为程序名ls,第二个参数为-al,第三个参数为/etc/passwd
    execl("/bin/ls", "ls","-al","/etc/passwd",(char*)0);
    return 0;
}

实例2

include <unistd.h>

int
main(void)
{
    char args[] = "-l";
    /*
     * 执行/bin目录下的ls,第一参数为程序名ls,
     * 第二个参数为-al,第三个参数为/etc/
     */
    execl("/bin/ls","ls","-al","/etc/",NULL);
    
    return 0;
}

上面的2个例子来自:https://blog.csdn.net/ahuang1900/article/details/38169769

excel的第一个参数是关键,第二个参数只是个名称而已,可以随便写——当然,为了代码的功能清楚,乱写也没有必要;

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lqw198421

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值