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).
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:
Output Screenshots:
Execution: ./MakeCopy srcfile destfile
My filename is main.c, So i used ./main
destfile.txt:
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 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 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...
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 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...
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 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...
Assume access control list of three files are given as below in Unix directory listing. (you will see something similar when you type ls -l in a unix system) Access Control FileName Group Owner Drw-rwxr-x Classess University Nick drwxr----- bills University Kate -rwxrw-rw- list OS_Class Sandra -rwxr-x--x Assignment2 OS_Class Nancy Narrate the permission given to the owner, group and everybody for each file or folder. Hint: d- directory (if it is a folder, otherwise -) r- read permission w- write...
C ++ Implement cat command The purpose of this assignment is to provide practice using the system calls we discussed for working with files on a UNIX system. You will be writing a basic implementation of the cat command using C++. Description As you should recall, the cat command takes a list of files as command line arguments. It then opens each file in turn, writing each file’s entire contents to standard output in the order they were supplied. You...
QUESTION 1 What will be the output of following Unix command: find / -name ‘*’ A. List all files and directories recursively starting from / B. List a file names * in / C. List all files in / directory D. List all files and directories in / directory QUESTION 2 Which command is used to extract a column/field from a text file / input. A. paste B. get C. cut D. tar QUESTION 3 Which command creates an empty...