Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

System Programming Assigment 2

In this assigment we made 3 different tasks.

All tests has been made on MacBook Pro with arm proccesor using UTM virtual machine to run gcc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0.

TaskA: Compare and Copy files tool

Compare

Cmp tool compares two files and returns 1 if they are equal or 0 if not. The tool supports additional flags (-v , -i). -v for verbose output. -i to ignore case size.

To run:

   make cmp
   ./cmp <file1> <file2> -v -i

Copy

Copy tool will copy a source file to a destination file. The tool supports additional flags (-v, -f). -v for verbose output. -f will force copy (will rewrite existing file if needed).

To run:

   make copy
   ./copy <file1> <file2> -v -f

TaskB: Dynamic libraries implementing

In this taks we wrote two simple dynamic libraries that converts characters they get. Also we wrote two simple tools that demnstrate dynamic library usage.

Libraries: CodecA - makes swaps every big char to small and small to big. CodecB - adds 3 to ascii of every char.

Tools: Encode - gets codec name and text, prints encoded text to the console Decode - gets codec name and text, prints decodedd text to the console

To run:

   make codecA codecB encode decode
   export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
   ./encode <codec> "some text"
   ./decode <codec> "some text"

TaskA and TaskB Example

image

image

TaskC: Shell Programm

This is a C program that implements a simple shell, which allows users to execute commands by typing them into the terminal. The shell supports basic features such as input/output redirection and piping.

Here is a brief overview of the program's functionality:

  • The program defines several functions to handle signal handling, input/output redirection, and command execution.
  • The main function enters an infinite loop, displaying a prompt and reading user input until the user types "quit".
  • If the user input contains a pipe character ("|"), the program splits the input into multiple commands and creates a pipeline of child processes to execute the commands.
  • If the user input does not contain a pipe character, the program simply forks a child process to execute the command.
  • In both cases, the child process sets up signal handling for Ctrl+c, redirects input/output if necessary, and executes the command using the execvp() function.
  • The parent process waits for the child process to exit and then repeats the loop.

Shell Programm 2.0

  • Stderr riderection 2>
  • Prompt change (prompt = myprompt)
  • echo command
  • echo $? returns last command status
  • cd implemented
  • !! implemented (last command rerun)
  • variables implemented ($varname = value) (echo $varname)
  • read implemented (another variable implementation) (read varname \n name)
  • if/else implemented (if [command] \n then \n [command 1] \n [command 2] ... else \n [command 1] \n [command 2] ... fi)

To run:

   make stshell
   ./shell

TaskC Example

image

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages