免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
linux下C程序插入執(zhí)行shell腳本

linux下C程序插入執(zhí)行shell腳本

最近在看深入理解計算機系統(tǒng),看到一個函數(shù)叫做execve(),這個函數(shù)很有意思,可以在一個進程插入另外一個進程執(zhí)行,但是又不像fork()一樣產(chǎn)生一個子進程,execve()插入的進程和原進程共享進程號,就好像執(zhí)行這進程就像執(zhí)行過程調(diào)用一般隨意。

函數(shù)原型如下:

int execve(const char *filename, char *const argv[], char *const envp[]);

EXAMPLE       The following program is designed to be execed by the second program below.  It just echoes its command-line one per line.           /* myecho.c */           #include <stdio.h>           #include <stdlib.h>           int           main(int argc, char *argv[])           {               int j;               for (j = 0; j < argc; j++)                   printf("argv[%d]: %s\n", j, argv[j]);               exit(EXIT_SUCCESS);           }       This program can be used to exec the program named in its command-line argument:           /* execve.c */           #include <stdio.h>           #include <stdlib.h>           #include <unistd.h>           int           main(int argc, char *argv[])           {               char *newargv[] = { NULL, "hello", "world", NULL };               char *newenviron[] = { NULL };               if (argc != 2) {                fprintf(stderr, "Usage: %s <file-to-exec>\n", argv[0]);                exit(EXIT_FAILURE);               }               newargv[0] = argv[1];               execve(argv[1], newargv, newenviron);               perror("execve");   /* execve() only returns on error */               exit(EXIT_FAILURE);           }       We can use the second program to exec the first as follows:           $ cc myecho.c -o myecho           $ cc execve.c -o execve           $ ./execve ./myecho           argv[0]: ./myecho           argv[1]: hello           argv[2]: world

插入一個shell腳本執(zhí)行:

#include <stdio.h>#include <stdlib.h>#include <unistd.h>intmain(int argc, char *argv[]){    char *newargv[] = { "/etc" };    char *newenviron[] = { NULL };    if (argc != 2)    {        fprintf(stderr, "Usage: %s <file-to-exec>\n", argv[0]);        exit(EXIT_FAILURE);    }    newargv[0] = argv[1];    execve(argv[1], newargv, newenviron);    perror("execve");   /* execve() only returns on error */    exit(EXIT_FAILURE);}

script.sh如下:

#!/bin/bashls 

執(zhí)行:

./execve ./script.sh

會在當前終端下輸出所有的文件

yca@ubuntu:~/桌面/hello$ ./execve ./script.sh 1          execve     hello1    hello3      hello5      hello_lex1.txt          execve.c     hello1.c  hello3.cpp  hello5.c   k_maxBubble          hello     hello1.o  hello3.o    hello5.o   k_max.cBubble.c      hello.c     hello2.c  hello3.s    hello5.s   lex.yy.cQuickSort.c   hello.lex  hello2.o  hello4      hello5.s1  script.shQuicksort1.c  hello.sh     hello2.s  hello4.c    hello51.s

很好很強大~~

3
0
(請您對文章做出評價)
博主上一篇:疑問:進程間通信
博主下一篇:文件描述符與進程間通信之關(guān)聯(lián)
首頁上一篇:基于Heritrix+Lucene的搜索引擎構(gòu)建(1)——網(wǎng)絡(luò)蜘蛛Heritrix
首頁下一篇:選擇HttpHandler還是HttpModule?
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
linux 編輯、編譯鏈接、執(zhí)行C語言并發(fā)程序
Main函數(shù)參數(shù)argc,argv說明
C語言學習教程第十章-文件(4)
成功來自每一天: 在c用使用perl
【C語言】12個有趣的C語言問答
【原創(chuàng)】自制編程語言-1 最小編程語言
更多類似文章 >>
生活服務
分享 收藏 導長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服