当前位置:网站首页>Process (present) : custom shell command line interpreter
Process (present) : custom shell command line interpreter
2022-08-02 05:00:00 【RNGWGzZs】
---------------------------------Come on!
There are few theories in this article, and of course the amount of code is very small, just the uploaded code.
#include#include#include#include#include#include#define MAX_ORDER 1024#define MAX_LINE 32int main(){//command inputchar cmd[MAX_ORDER];char* line[MAX_LINE]; //command parameter split//The shell script is always runningwhile(1){printf("\n[[email protected] my_shell]# ");fgets(cmd,MAX_ORDER,stdin); //readcmd[strlen(cmd)-1]='\0'; //solve\n//printf("%s\n",cmd);line[0]=strtok(cmd," ");int i=1;while(line[i]=strtok(NULL," ")){i++;}//Create a child process to callpid_t id=fork();if( id == 0 ){//child executesexecvp(line[0],line);// who to execute and how to execute}int status=0;pid_t ret=waitpid(id,&status,0); //At this point the parent process just needs to waitif(ret > 0){printf("exit code:%d\n",WEXITSTATUS(status));}}return 0;}
The final code is the paragraph.
Good luck~
边栏推荐
猜你喜欢
随机推荐
Case | industrial iot solutions, steel mills high-performance security for wisdom
[Arduino connected to GPS module (NEO-6M) to read positioning data]
rosdep update失败解决办法(亲测有效)
LT9211芯片资料分享
GM8775C MIPI转LVDS调试心得分享
GM8775C规格书,MIPI转LVDS,MIPI转双路LVDS分享
龙讯LT6911系列C/UXC/UXB/GXC/GXB芯片功能区别阐述
Arduino lights up nixie tubes
2020 - AAAI - 图像修复 Image Inpainting论文导读 -《Region Normalization for Image Inpainting》
TeamCode 产品 UI 全新升级,快来体验吧
[Arduino connects the clock module to display the time on LCD1602]
408-Binary tree-preorder inorder postorder level traversal
【科普贴】MDIO接口详解
【plang1.4.3】语言新特性:集合
408-二叉树-先序中序后序层次遍历
GM8284DD,GM8285C,GM8913,GM8914,GM8905C,GM8906C,国腾振芯LVDS类芯片
增量编译技术在Lightly中的实践
功率计,物联网,智能插座电路设计【毕业设计】
【Connect the heart rate sensor to Arduino to read the heart rate data】
如何使用 PHP 实现网页交互