Homework d: Unix Shell and History Feature - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

Homework d: Unix Shell and History Feature

Description:

creating the child process and executing the command in the child ... www3.interscience.wiley.com:8100/legacy/college/silberschatz/0471694665/sou rce/source.zip ... – PowerPoint PPT presentation

Number of Views:298
Avg rating:3.0/5.0
Slides: 10
Provided by: skhu
Category:

less

Transcript and Presenter's Notes

Title: Homework d: Unix Shell and History Feature


1
Homework d Unix Shell and History Feature
2
Problem Description
  • Implement a shell interface
  • accept user commands
  • execute each command in a separate process
  • creating the child process and executing the
    command in the child
  • modifying the shell to allow a history feature
  • Modify the source in chapter 3
  • http//www3.interscience.wiley.com8100/legacy/col
    lege/silberschatz/0471694665/source/source.zip
  • Example
  • cat /etc/fstab
  • parent process waits for the child to exit
  • cat /etc/fstab
  • (child process to run in the background)
  • ltControlgtltCgt
  • List the recent 10 commands entered
  • r x
  • run the most recent command with r the first
    letter of that command.
  • ltControlgtltDgt
  • terminate the shell

3
Motivation
  • Try to learn the process concept using system
    calls
  • fork()
  • exec() family
  • signal handling

4
The simple shell
  • setup()
  • read the users next command up to 80 characters
  • parse the command into separate tokens (and form
    an argument vector for the command)
  • if end with , the command is in background
  • example ls -l
  • argv0 becomes ls and argv1 becomes -l
  • main()
  • print the prompt COMMAND-gt
  • invoke setup()
  • create a child process
  • child process will invoke execvp()
  • if background, parent wont wait.

5
setup()
  • read in the next command line
  • separate it into distinct tokens using whitespace
    as delimiters
  • modify the args parameter to hold array of
    pointers to
  • current user command
  • arguments
  • NULL

6
Creating a Child Process
  • fork a child process using fork()
  • after setup(), invoke
  • execvp(char command, char params)
  • execvp(args0, args)
  • wait or not wait by checking if it is a
    background job

7
Creating a History Feature
  • Provide a history feature
  • access up to the 10 most recently entered
    commands
  • commands numbered starting at 1 to grow larger
    even past 10, say 35 commands, and the most
    recent are numbered 26 to 35.
  • list the recent commands by pressing
    ltControlgtltCgt, the SIGINT signal.

8
Signal Handling
  • example events
  • division by zero, illegal memory access, user
    entering ltControlgtltCgt,etc.)
  • signal handling
  • ignoring the signal
  • using the default signal handler
  • providing a separate signal-handling function

9
User defined signal handling
  • include /usr/include/sys/signal.h
  • struct sigaction handler
  • handler.sa_handler user_defined_haandler
  • sigaction(SIGINT, handler, NULL)
Write a Comment
User Comments (0)
About PowerShow.com