1. Homepage
  2. Programming
  3. COMP3511 Operating System - PA1: Simplified Linux Shell

COMP3511 Operating System - PA1: Simplified Linux Shell

Engage in a Conversation
UST Hong KongCOMP3511Operating SystemSimplified Linux ShellShellC

COMP3511 Operating System (Fall 2023)
CourseNana.COM

PA1: Simplified Linux Shell CourseNana.COM

Release on 23-Sep (Sat) Due on 8-Oct (Sun) at 23:59 CourseNana.COM

Introduction CourseNana.COM

This project aims to enhance students' understanding of process management, input and output redirection, and inter-process communication within an operating system. By completing this project, students will gain the necessary skills to implement a practical system program using relevant Linux system calls, enabling them to effectively manage processes and facilitate seamless communication between processes. We highly recommend students to attend the project-related lab. CourseNana.COM

Program Usage CourseNana.COM

Your goal is to implement a simplified version of a Linux shell program. The program name is myshell.
Here is the simplest usage:
CourseNana.COM

$> ./myshell
Myshell (pid=4442) starts
ITSC> exit
Myshell (pid=4442) ends
$>

$> represents the system shell prompt (i.e., your system shell, not our PA1 shell program). The command (./myshell ) launches our PA1 shell program. CourseNana.COM

When myshell starts, it displays the process ID (pid). Please note that the process ID will be different every time when you launch the PA1 shell program. CourseNana.COM

Our shell program supports the exit command. When your shell program exits, it should display the process ID. The start process ID and the end process ID must be the same. CourseNana.COM

After that, our shell program terminates. You can type commands to the system shell again. CourseNana.COM

GCC compiler in the lab environment CourseNana.COM

In this semester, gcc version 11 is the default gcc compiler installed in our lab environment. CourseNana.COM

$> gcc --version
gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4)
Copyright (C) 2021 Free Software Foundation, Inc.

Getting Started
CourseNana.COM

You don’t need to start from scratch. myshell_skeleton.c is the starting point.
To start, please remember to rename the file as
myshell.c CourseNana.COM

Read carefully the documentation in the provided code. The skeleton code file provides you many useful helper functions. Necessary programming concepts will also be introduced during the related lab(s). CourseNana.COM

Please note that C programming language (instead of C++) MUST be used to complete this assignment. C is not the same as C++. C99 option is added to allow a more flexible coding style. Here is the command to compile myshell.c CourseNana.COM

$> gcc -std=c99 -o myshell myshell.c

Restrictions CourseNana.COM

In this assignment, you CANNOT use system or popen function defined in the C Standard library. The purpose of the project assignment is to help students understand process management and inter-process communication. These 2 functions are too powerful which can directly process the whole command (including pipe and redirection). CourseNana.COM

You should use the related Linux system calls such as pipe and dup2. When connecting pipes, POSIX file operations such as read, open, write, close should be used. You should not use fread, fopen, fwrite, fclose from the C standard library. CourseNana.COM

Assumptions CourseNana.COM

You can assume that the input format is valid.
There won’t be commands with both redirection and pipe at the same time.
We assume that each command line has at most 256 characters (including NULL) We assume that there exists at most 8 pipe segments.
Each pipe segment may have at most 8 arguments
CourseNana.COM

Note: execvp system call needs to store an extra NULL item to represent the end of the parameter list. Thus, you will find the constant is set to 9 (instead of 8) in the starter code. For details, please read the comment lines provided in the starter code CourseNana.COM

We assume that there exists at most 1 input redirection and at most 1 output redirection. For output redirection, you can assume the output file does not exist in the current working directory. In other words, the grader will remove the temporary output text files (i.e., tmp*.txt).
You only need to handle 2 space characters: tab (
\t) and space( ). CourseNana.COM

Feature 1: Start/End the Shell
CourseNana.COM

Implement the exit command handling. Here is a sample test case: CourseNana.COM

$> ./myshell
Myshell (pid=11004) starts
ITSC> exit
Myshell (pid=11004) ends
$>

You need to replace ITSC with your own ITSC account name. For example, if your ITSC account is cspeter@connect.ust.hk, you should replace ITSC using cspeter.
For post-graduate students taking this course, DON’T use ITSC alias.
CourseNana.COM

Feature 2: Customized Ctrl-C (SIGINT) handling CourseNana.COM

Implement a simple customized Ctrl-C (SIGINT) handling. Here is a sample test case: CourseNana.COM

$> ./myshell
Myshell (pid=6449) starts
ITSC>
^CMyshell (pid=6449) terminates by Ctrl-C $> CourseNana.COM

From the keyboard, press Ctrl-C on the shell prompt. You should see ^C on the screen. A customized message will be displayed before terminating myshell. CourseNana.COM

Feature 3: Redirection CourseNana.COM

Instead of typing the command on the console, the input can be redirected from a text file. The file input redirection feature can be completed by using the dup/dup2 system calls (discussed in the lab). The key idea is to close the default stdin and replace the stdin with the file descriptor of an input file. CourseNana.COM

We can use the following command to count the number of lines of the file (myshell.c). Assume the file is in the current directory. A sample input file redirection usage: CourseNana.COM

                     $> wc -l < myshell.c

Like input redirection, the output can also be redirected to a text file. The file output redirection feature can be completed by using the dup/dup2 system calls. The key idea is to close the stdout and replace the stdout with the file descriptor of an output file. CourseNana.COM

We can use the following command to redirect the output of the ls command to an output text file (tmp_out_only.txt). Here is a sample output redirection usage: CourseNana.COM

                 $> ls -lh > tmp_out_only.txt

Please note that we have test cases with a mix of both input and output redirection. For example: CourseNana.COM

          $> wc -l < myshell.c > tmp_in_then_out.txt
          $> wc -l > tmp_out_then_in.txt < myshell.c

In this project, you are required to handle at most 1 input redirection (<) and at most 1 output redirection (>) in a command. CourseNana.COM

Feature 4: Multi-level pipe CourseNana.COM

In a shell program, a pipe symbol (|) is used to connect the output of the first command as the input of the second command. For example, CourseNana.COM

$> ls | sort CourseNana.COM

The ls command lists the contents of the current working directory. As the output of ls is already connected to sort, it won’t print out the content to the screen. After the output of ls has been sorted by sort command, the sorted list of files appears on the screen. In this project, you are required to support multiple-level pipes with at most 8 pipe segments CourseNana.COM

Some Examples CourseNana.COM

Example 1: CourseNana.COM

$> echo a1 a2 a3 a4 a5 a6 a7

The above command has 1 pipe segment
That segment has 8 arguments
This above example is useful to test the upper bound of the number of arguments
CourseNana.COM

Example 2: CourseNana.COM

$> ls | sort -r | sort | sort -r | sort | sort -r | sort | sort -r CourseNana.COM

The above command has 8 pipe segments.
Each segment has either 1 argument or 2 arguments.
The above example is useful to test the upper bound of the number of pipe segments
CourseNana.COM

Example 3: CourseNana.COM

$> ls -l -h CourseNana.COM

The input may contain several empty space characters.
The above example is useful to test whether you handle tabs and spaces correctly.
CourseNana.COM


Given Test Cases CourseNana.COM

The given test cases are released. You can see the exact commands in the following table: CourseNana.COM

Test Case (all characters are in one line) CourseNana.COM

Description CourseNana.COM

The exit command handling is given in the skeleton code. CourseNana.COM

$> ./myshell
Myshell (pid=11004) starts
ITSC> exit
Myshell (pid=11004) ends

Make sure ITSC is replaced with your own ITSC account name. Otherwise, you will lose points in this simple case. CourseNana.COM

Running the simplest ls command CourseNana.COM

After running this command, you should see the names of the file in the current working directory CourseNana.COM

ls -l -h CourseNana.COM

Running a command and there are some tabs and spaces in between the parameters. CourseNana.COM

You should see the output which is equivalent to running the command: ls -lh CourseNana.COM

echo a1 a2 a3 a4
a5 a6 a7

This test case is useful to test the upper bound of the number of arguments. CourseNana.COM

wc -l < myshell.c

Assume myshell.c is located in the same directory of the executable of the myshell program, this command counts the number of lines of myshell.c CourseNana.COM

For example, if your current myshell.c contains 200 lines, it should display a number 200 CourseNana.COM

ls -lh >
tmp_out_only.txt

The output of the command: ls -lh will be redirected to a text file tmp_out_only.txt
You can assume tmp_out_only.txt does not exist in the current directory.
CourseNana.COM

ls | sort CourseNana.COM

Press Ctrl-C via
keyboard

This test case is a basic 2-level pipe command CourseNana.COM

A customized message will be displayed before terminating myshell CourseNana.COM

ls | sort -r | sort
| sort -r | sort |
sort -r | sort |
sort -r

This test case is useful to test the upper bound of the number of pipe segments CourseNana.COM

Hidden Test Cases CourseNana.COM

The hidden test cases won’t be released before the project deadline. You cannot see the exact commands, but you can see the description about the hidden test cases. CourseNana.COM

Code Description CourseNana.COM

Hidden01 CourseNana.COM

This test case involves the system shell and 3 myshell programs I call these myshell programs: myshell1, myshell2, and myshell3 CourseNana.COM

In the system shell, run ./myshell (i.e., start myshell1) Run ./myshell inside myshell1 (i.e., start myshell2) Run ./myshell inside myshell2 (i.e., start myshell3) CourseNana.COM

Run the ps command inside myshell3 to show the current process table. Here is a sample process table (the table is different every time): CourseNana.COM

PID TTY
  10945 pts/1
  12113 pts/1
  12114 pts/1
  12115 pts/1
  12116 pts/1
TIME CMD
00:00:00 tcsh
00:00:00 myshell
00:00:00 myshell
00:00:00 myshell
00:00:00 ps

Run exit to quit myshell3, myshell2, and myshell1
The control should be returned to the system shell.
Run ps inside the system shell. Here is a sample process table:
CourseNana.COM

PID TTY
 10945 pts/1
 12117 pts/1
 TIME CMD
00:00:00 tcsh
00:00:00 ps

Please note that all process IDs may be different every time. CourseNana.COM

Hidden02 CourseNana.COM

A mix of input redirection and output redirection (input, and then output) After that, run cat command to display the content of the text file. CourseNana.COM

Hidden03 CourseNana.COM

A mix of input redirection and output redirection (output, and then input) After that, run cat command to display the content of the text file. CourseNana.COM

Hidden04 CourseNana.COM

Run a 2-level pipe command.
After that, run another 2-level pipe command.
CourseNana.COM

Hidden05 CourseNana.COM

Run a 2-level pipe command.
After that, run another 3-level pipe command.
CourseNana.COM

Hidden06 CourseNana.COM

Start myshell1, myshell2, myshell3 like Hidden01
In myshell3, press Ctrl-C
All shells should be terminated with the same customized handler
CourseNana.COM

Sample Executable CourseNana.COM

The sample executable (runnable in a CS Lab 2 machine) is provided for reference. After the file is downloaded, you need to add an execution permission bit to the file. For example: CourseNana.COM

                     $> chmod u+x myshell

Development Environment CourseNana.COM

CS Lab 2 is the development environment. Please use one of the following machines (csl2wkXX.cse.ust.hk), where XX=01...40. The grader will use the same platform. In other words, “my program works on my own laptop/desktop computer, but not in one of the CS Lab 2 machines” is an invalid appeal reason. Please test your program on our development environment (not on your own desktop/laptop) thoughtfully, even you are running your own Linux OS. Remote login is supported on all CS Lab 2 machines. CourseNana.COM

Marking Scheme CourseNana.COM

  1. Please fill in your name, ITSC email, and declare that you do not copy from others. A template is already provided near the top of the source file. CourseNana.COM

  2. Automatically 0 marks if system or popen function is used in your code CourseNana.COM

  3. Correctness of the given test cases (50 marks) CourseNana.COM

    1. The given test cases are equally weighted CourseNana.COM

    2. The sum will be normalized to 50 marks CourseNana.COM

    3. There won’t be partial credits for each test case CourseNana.COM

    4. You cannot hard-code the given test cases. CourseNana.COM

i. For example, your program cannot simply use strcmp to compare the text “ls” (one of the given test cases), and then run the “ls” command using execlp(“ls”,”ls”). It is hard coding because your program only handles the given test cases. CourseNana.COM

4. Correctness of the hidden test cases (50 marks) CourseNana.COM

a. The hidden test cases are equally weighted.
b. The sum will be normalized to 50 marks.
c. There won’t be partial credits for each test case.
CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
UST Hong Kong代写,COMP3511代写,Operating System代写,Simplified Linux Shell代写,Shell代写,C代写,UST Hong Kong代编,COMP3511代编,Operating System代编,Simplified Linux Shell代编,Shell代编,C代编,UST Hong Kong代考,COMP3511代考,Operating System代考,Simplified Linux Shell代考,Shell代考,C代考,UST Hong Konghelp,COMP3511help,Operating Systemhelp,Simplified Linux Shellhelp,Shellhelp,Chelp,UST Hong Kong作业代写,COMP3511作业代写,Operating System作业代写,Simplified Linux Shell作业代写,Shell作业代写,C作业代写,UST Hong Kong编程代写,COMP3511编程代写,Operating System编程代写,Simplified Linux Shell编程代写,Shell编程代写,C编程代写,UST Hong Kongprogramming help,COMP3511programming help,Operating Systemprogramming help,Simplified Linux Shellprogramming help,Shellprogramming help,Cprogramming help,UST Hong Kongassignment help,COMP3511assignment help,Operating Systemassignment help,Simplified Linux Shellassignment help,Shellassignment help,Cassignment help,UST Hong Kongsolution,COMP3511solution,Operating Systemsolution,Simplified Linux Shellsolution,Shellsolution,Csolution,