linux 中shell的简单写法
来源:互联网 发布:矿山建设工程预算软件 编辑:程序博客网 时间:2024/04/26 20:13
#include<stdio.h>#include<unistd.h>#include<stdlib.h>#include<sys/types.h>#include<sys/wait.h>int main(){char buf[128];while(1){printf("[test@my-host-name myshell]");fflush(stdout);sleep(3);ssize_t _s = read(0,buf,sizeof(buf) - 1);if(_s > 0){buf[_s-1] = '\0';}else{perror("read");return 1;}char* argv[32];argv[0] = buf;int i = 1;char *start = buf;while(*start){if(isspace(*start)){*start = '\0';start++;argv[i] = start;i++;// printf("i = %d\n",i);continue;}start++;}// printf("NULL : i = %d\n",i);argv[i] = NULL;pid_t id = fork();if(id < 0){perror("fork");}else if(id == 0){//childexecvp(argv[0],argv);exit(1);}else{int status = 0;pid_t ret = waitpid(id, &status,0);if(ret > 0 && WIFEXITED(status)){// printf("exit code:%d\n",WEXITSTATUS(status));}else{//fatherperror("waitpid");}}}return 0;}
0 0
- linux 中shell的简单写法
- Linux下简单Shell 脚本的写法
- 记录一下shell简单写法
- Linux的简单shell脚本中修改文件操作
- Linux的简单shell脚本中修改文件操作
- Linux的简单shell脚本中修改文件操作
- Linux的简单shell脚本中修改文件操作
- linux中新增一个shell命令最简单的方法
- linux下简单的makefile写法
- ArcGIS中Featurelayer的简单写法
- JavaScript中简单的--抽奖写法
- Linux shell的简单学习
- Linux简单的shell脚本
- Linux 简单的shell实现
- 一个简单的Linux Shell
- 【Linux】shell的简单模拟
- linux shell$()的简单用法
- Linux Shell if 常用写法
- 切面条
- 基于对话交互的学习
- C++Primer 第一章
- codeforce round 399# E
- 改革春风吹满地
- linux 中shell的简单写法
- 以太网、局域网、互联网区别
- Android数据库框架greenDao学习笔记(一)----集成
- RNN的四种代表性扩展—Attention and Augmented Recurrent Neural Networks(一)
- 3、查找jar包对应的坐标
- Easyui笔记5:如何实现datagrid右键插入删除?
- 在 Visual Studio 中使用代码映射可视化和了解代码
- 用户推荐系统_python 代码
- GET和POST