Answered You can hire a professional tutor to get the answer.

QUESTION

Instruction:The history feature introduced in Lab 3is not persistent, i. the shell program cannot keep the command history across different runs.

Instruction:The history feature introduced in Lab 3is not persistent, i.e. the shell program cannot keep the command history across different runs. To make it persistent, you need to modify your shell program to save the contents of the history buffer into a file before it exits.In addition, the shellprogram needs to reload the previous commands from the saved history file once you start the program. You can name the command history file as "<your-userid>.history". For the first time execution of your shell program, the history buffer should be empty and you can create such history file when exiting the program.More specifically, you need to modify the main()function and possibly other related functions as well in the file shell.c. In the initialization phase, you need to check the existence of the command history file. If it exists, you should open the file and load the command history into the history buffer. Otherwise, you just initialize the history buffer as empty buffer. At the end of the main()function and other possible exit points of the program, you should save the current command history into the history file for future uses.Note: name the history file in the way "<your-userid>.history"to differentiate yours from others. You can decide the format of the history fileas long as it can bereloaded for future program execution.

My code cannot work properly, can anyone help me?

#include <errno.h>

#include <signal.h>

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/wait.h>

#define MAX_LINE 80 /* 80 chars per line, per command, should be enough.

*/

#define NUM_HIST 10 /* Remember upto 10 command histories. */

char histories[NUM_HIST][MAX_LINE/2+1][MAX_LINE];

int backgrounds[NUM_HIST];

int num_hist = 0;

int latest = -1;

/*restore histroy frm file*/

void print_cmd(int idx);

void restorHistory()

{

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question