Question

Using Unix processes Submit a README file that lists the files you have submitted along with...

Using Unix processes

Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README.


MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode.


ForkCopy.c : Write a C program that creates a new process to copy the files using the MyCopy. This program should spawn a new process using fork system call. Then use execl to execute MyCopy program. The source and destination file names presented as command-line arguments should be passed to execl as system call arguments. The main process waits for completion of copy operation using wait system call.


PipeCopy.c : Write a C program that forks two processes one for reading from a file (source file) and the other for writing (destination file) into. These two programs communicate using pipe system call. Once again the program accomplishes copying files, the names of which are specified as command-line arguments.


Use CompareTime.c for time to compare the three versions of the file copy programs as specified above and write an explanation about the results in Prj1README. You can either get the results through PreTest program or linux terminal with the command below.
./ComapareTime <ProgramToTest> <src> <dst> <bufferSize>


MyShell.c : Write a shell-like program that illustrates how UNIX spawns processes. This simple program will provide its own prompt to the user, read the command from the input and execute the command. It is sufficient to handle just ``argument- less'' commands, such as ls and date.


MoreShell.c :Make the mini-shell (from the previous part) a little more powerful by allowing arguments to the commands. For example, it should be able to execute commands such as more filename and ls –l ./tmp etc. (MoreShell.c MoreShell)


DupShell.c : Add to the mini-shell ability to execute command lines with commands connected by pipes. Use dup system call to redirect IO. Example: ls -l | wc . (DupShell.c DupShell).


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Do like and comment if you have any queries.

Note:

As per Chegg answering guidelines, I am allowed to answer a single question when multiple questions are posted. So, please post others as a different question.

Code to copy:

   #include <stdio.h>
   #include <inttypes.h>
   #include <string.h>
   #include <errno.h>

   /* Size of the data blocks copied in bytes */
   #define DATA_BLOCKS_SIZE 1024

   int main(int argc, char const *argv[]) {
       /* Check number of arguments and print manual */
       if(argc < 3) {
           printf("ERROR: Too few arguments. Usage: ./MakeCopy source destinationination\n");
           return 3;
       }

       /* Open file pointer for source and handle error */
       FILE *source = fopen(argv[1], "r");
       if(source == NULL) {
           printf("ERROR: Unable to open source file \"%s\" (%s)\n", argv[1], strerror(errno));
           return 1;
       }

       /* Open file pointer for destinationination and handle error */
       FILE *destination = fopen(argv[2], "w+");
       if(destination == NULL) {
           printf("ERROR: Unable to create destinationination file \"%s\" (%s)\n", argv[2], strerror(errno));
           fclose(source);
           return 2;
       }

       /* Create buffer for efficent copying and counters */
       uint8_t buffer[DATA_BLOCKS_SIZE];
       uint16_t read_Data_Count = 0;
       uint64_t copied_Data_Count = 0;

       /* Copy blocks */
       while((read_Data_Count = fread(buffer, 1, DATA_BLOCKS_SIZE, source)) > 0) {
           fwrite(buffer, 1, read_Data_Count, destination);
           copied_Data_Count += read_Data_Count;
           printf("%" PRIu64 " bytes copied...\n", copied_Data_Count);
       }

       /* Check if a error occured while reading the source file */
       if(ferror(source)) {
           printf("ERROR: failure while reading the source file!\n");
           return 3;
       }

       /* Check if a error occured while writing the destinationination file */
       if(ferror(destination)) {
           printf("ERROR: failure while writing the destinationination file!\n");
           return 4;
       }

       /* Print success and exit */
       printf("SUCCESS.\n");
       return 0;
   }

srcfile.txt:

srcfile.txt saved 1 Hi, Chegg expert

Output Screenshots:

Execution: ./MakeCopy srcfile destfile

My filename is main.c, So i used ./main

} ./main srcfile.txt destfile.txt 16 bytes copied... SUCCESS.

destfile.txt:

destfile.txt saved 1 Hi, Chegg expert

Add a comment
Know the answer?
Add Answer to:
Using Unix processes Submit a README file that lists the files you have submitted along with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Unix processes Submit a README file that lists the files you have submitted along with...

    Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...

  • this is the code you should use from already existing shell i created . Just gothrough...

    this is the code you should use from already existing shell i created . Just gothrough the programand execute that command.and execute in linux. It takes the command from the user and execute. #include<stdio.h>i #include<stdlib.h> #include<string.h> int main() { //cmd1 is the ,hr variable which holds the commands char cmd1[10]; printf("Enter the command without options like ls or date"); scanf("%s",&cmd1); printf("%s\n",cmd1); //system function is used for to run the unix commad, it use system(cmd1); return 0; } #include<stdlib.h> int main()...

  • e) In the context of Unix file system , what does "path" means? f) Write down...

    e) In the context of Unix file system , what does "path" means? f) Write down the absolute path for the main.cpp in the timeproj directory g)Write down the relative path from inside timeproj directory to the prgm1.cpp file h)Write down the Unix commands and key strokes needed to create a new sourcefile named time.cpp and then save it to disk using the pico editor. i) In Unix each file has three access modes, namely r,w, and x. 1) Write...

  • Description: Merge two or more text files provided by the user into a new text file...

    Description: Merge two or more text files provided by the user into a new text file where the names of the text files to join and the output text file are provided to the program using command line arguments. Purpose: This application provides experience working with command line arguments, writing files to disk, reading files from disk, working with exceptions, and writing programs in C#/.NET. Requirements: Project Name: DocumentMerger2 Target Platform: Console Programming Language: C# In a previous challenge, Document...

  • UNIX is all about manipulating files and input/output streams fluidly, so it is important to get a strong grasp of how...

    UNIX is all about manipulating files and input/output streams fluidly, so it is important to get a strong grasp of how this fundamentally works at the system call level to understand higher-level system programming concepts. Every program automatically has three file descriptors opened by the shell standard input standard output standard error 1 2 One can use read and write other open file. Normally, standard input and output on the terminal are line-buffered, so, for example, the specified number of...

  • COSC 3411 /ITAP 3411 Homework (UNIX Shell Commands) How would you ensure that all ordinary files...

    COSC 3411 /ITAP 3411 Homework (UNIX Shell Commands) How would you ensure that all ordinary files created by you have rw-rw---- as default permissions? How would you sort in the background a file called "bad.txt", and place the results in a file called "sort.txt"? Archive the contents of your home directory (including any subdirectories) using tar. Compress the tar archive with gzip. Now extract their contents. Use the “find” command to locate in /docs and /usr/docs all files that Begin...

  • Part 1: Create a shell script that returns a full name associated with a userid specified...

    Part 1: Create a shell script that returns a full name associated with a userid specified in the command line argument. • Use the names found in /acct/common/CSCE215-Spring19. • Your shell script should be named “findName.sh” – Example usage: $ ./findName.sh seiei SETSUNA F SEIEI $ – Your shell script must either: Return the full name associated with the userid or Return an error message if the command line arguments are not equal to 1. or Return the message “Sorry...

  • Unix/Linux The purpose of this lab is to practice the commands to manage and organize files...

    Unix/Linux The purpose of this lab is to practice the commands to manage and organize files and directories: How would one go about this? Thanks. Task 1: Preliminaries: 1) If you have not already done so, create a directory called bin under your HOME directory. 2) If you have not already made a copy (using ftp) of the file called famous.dat from the Assignment#1, do that now. 3) Make bin the active/working directory. Task 2: Perform all of the following...

  • In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use: 0 st...

    In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use: 0 standard input (stdin) 1 standard output (stdout) 2 standard error (stderr) By default, the command interpreter (shell) reads keyboard input from file descriptor 0 (stdin) and writes output to file descriptor 1 (stdout), which appears on the screen. As you explored in Lab 2, input/output can be...

  • These are the questions in intro to os and unix. Your efforts are appreciated. Thank you...

    These are the questions in intro to os and unix. Your efforts are appreciated. Thank you very much ! q1) [2] Give an abstract, high-level description of what a computer is. q2) [5] List the elements of a Von Neumann Machine. q3) [3] Name the two types of software, and give a brief description of each. q4) [2] What are the 2 Roles/Purposes of the OS? q5) [5] What are the OS's management tasks? q6) [1] What is a process?...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT