当前位置:网站首页>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~
边栏推荐
猜你喜欢
随机推荐
idea中创建jsp项目详细步骤
【科普贴】SPI接口详解
408-Binary tree-preorder inorder postorder level traversal
MIPI解决方案 ICN6202:MIPI DSI转LVDS转换芯片
关于IIC SDA毛刺的那些事
Host your own website with Vercel
D类音频功放NS4110B电路设计
proteus数字电路仿真——入门实例
NSIS来自己设定快捷方式的图标
案例|工业物联网解决方案·智慧钢厂高性能安全数采
2019 - ICCV - 图像修复 Image Inpainting 论文导读《StructureFlow: Image Inpainting via Structure-aware ~~》
uniCloud address book combat
【plang 1.4.3】定时器的使用
简单的RC滤波电路
IDEA2021.2安装与配置(持续更新)
引擎开发日志:重构骨骼动画系统
引擎开发日志:集成Bullet3物理引擎
联阳IT6561|IT6561FN方案电路|替代IT6561方案设计DP转HDMI音视频转换器资料
振芯GM7123C:功能RGB转VGA芯片方案简介
Flame sensor connected with Arduino









