#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <wait.h>
#include <string.h>
#include <signal.h>
#define MAX_LINE 80 /* 80 chars per line, per command, should be enough. */
#define BUFFERSIZE 11
typedef struct{
int number;
char com[MAX_LINE];
}command;
command buffer[BUFFERSIZE];
int buffer_pointer;
int setup(char inputBuffer[], char *args[],int *background);
void print(){
int i;
fflush(stdout);
write(STDOUT_FILENO,"\n",1);
for(i = (buffer_pointer - 1) % BUFFERSIZE;\
i != (buffer_pointer % BUFFERSIZE) && buffer[i].number;\
i = (i - 1 + BUFFERSIZE) % BUFFERSIZE ){
printf("%d\t%s",buffer[i].number,buffer[i].com);
fflush(stdout);
}
}
void handle_SIGINT(){
print();
signal(SIGINT, SIG_IGN);
return;
}
/**
* setup() reads in t
操作系统编程作业:UNIX Shell and History Feature
最新推荐文章于 2024-07-04 15:11:00 发布
这篇博客探讨了如何在操作系统编程中实现UNIX Shell和历史功能。文章通过C语言代码展示了读取命令行、处理命令参数、以及信号处理等方面的操作,特别是如何处理命令历史记录并实现`r`命令来重新执行历史命令。
摘要由CSDN通过智能技术生成