ahmmkh / Cat-Program-with-System-Calls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CAT Command Implementation in C

This program is designed to imitate the implementation of the cat command using various system calls like open(), close(), read(), write(). The program is completely written in C, and uses the default compiler for FreeBSD which uses the command cc to get compile.

How to run the program

  • Clone or download this repository
  • Navigate to the directory and open it on terminal
  • Compile the source code using cc mycat.c
  • Change the name of the executable to mycat using the command mv a.out mycat
  • Run the command ./mycat file1.txt file 2.txt file3.txt - you can replace files with whatever files you would like

System Calls

  • open(): The open() system call opens the file specified by file name. and takes a second argument of flags.
  • close(): The close() system call closes the file after finishing I/O operation
  • read(): read() reads up to an x number of bytes from a certain file into the buffer. A buffer has to be created first.
  • write(): write() writes up to an x number bytes from the buffer starting at a certain point to the file referred to in the function declaration.
  • perror(): perror() prints a system error message.

Flags

  • O_RDONLY: short for Read Only

Experiment

  • ./mycat file1.txt file2.txt file3.txt: output from each file will be printed to standard output.
  • ./mycat file100.txt: an error will be printed to standard output.
  • ./mycat: no output will be printed.
  • ./mycat file1 | grep string1: A line containing "string1" will be printed.

Assignment By: Ahmed SalahEldin Farouk Elkashef - 1410216

About


Languages

Language:C 100.0%