Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For Part II question 1 please do question according to point 15 - ping -a -A -c count -f -s packetSize destination Text copy of

For Part II question 1 please do question according to point 15 - ping -a -A -c count -f -s packetSize destination

image text in transcribedimage text in transcribedimage text in transcribed

Text copy of file -

Part II: 14 marks For this assignment you are assigned one of the commands listed below along with only the flags listed next to it. The # of your command matches the last 2 digits of your student number % 20, which means if your student # ends with 13, 33, 53, 73 or 93 (the tens digit is odd) you are assigned the man command, but if your # ends with 00, 20, 40, 60 or 80 (the tens digit is even) your command is vim. For this exercise the name of your C source file name should be the name of the command, but in all caps so that you are not running the actual command, ie: CURL.c , not curl.c Each of the above is an actual Unix command. Review the man page information on the flags specified for the command youve been assigned. 0. vim -A -b -O nWindows R -w logfile fileLIst 1. zip -d -e -i pattern o -P password zipFileDestination filesToZip 2. cp -f -i -p mode -t startNum s source(s) destination 3. curl -a -e url -h -m seconds -n urlLIst 4. egrep -A num -B num -c i -v pattern fileList 5. file -b f nameFile -F separator h -i fileList 6. gcc -g -O level -o outfile -S -E fileList 7. last -a -d -f file -n num -R userList 8. killall -i -r -q -s signalName -u user commandList 9. ln -f -i -S suffix -t directory -v fileList 10. locate -c -d path -i -n limit -S fileList 11. lpr -C title -h -P destination -m -r fileList 12. mail -i -n -s subject -v -u user fileList 13. man -E -M path -k -P pager -w command 14. php -a -c path -e -l -T count file args 15. ping -a -A -c count -f -s packetSize destination 16. sed -e expression -l length -n -r -s fileList 17. sort -d -k field.chars -r -t sep u fileList 18. su -c command -f -l -m -s shell user args 19. touch -c -d date -h -m -r refFile fileList 20. tree -a -F -L level q -T title directoryList Implement a getopt loop in C that captures your assigned flags and then, after the loop, report on which flags have been set. Please note - you dont have to implement the actual command. All you have to do is demonstrate that you can capture the flags correctly. The steps to implement this are: a) Create a data structure FLAGS specific to your command. The field names in this data structure should reflect the purpose of the flag based its man page description. The data type of each flag should be appropriate as well boolean, integer, double or char *. If there is no argument then it should be boolean, otherwise the datatype should be the determined from the man page description. (2 marks) b) Write a getopt loop with an option string that captures each of the flags. If a flag takes an argument the option is always followed by a colon. (4 marks) c) After the loop write a block of code that verifies that each of the flags and arguments were properly captured then lists the remaining non-flag arguments. Note you can place debugging code inside the loop but verification must take place after the loop in case there are accidental side effects. (2 marks) d) A flag with an optional argument must have that argument directly attached to it and is specified with 2 colons after the flag character in the option string. Add an extra flag with an optional argument. ie: xyp::z will use -p123 not -p 123 (2 marks) e) Create a shell script to test your program. (4) i. Test with no flags and multiple trailing arguments. Verify that all FLAGS variables are set to their default. ii. Test with only the flags that do not take an argument. iii. Test with the flags that do take an argument. iv. Test with all flags in a random order. v. Test with a mix of 3 flags chosen randomly in a random order. vi. Write a status statement indicating whether or not your program worked. If you uncovered a bug, explain what it is. Your shell script will look something like this, but reflect the proper usage of your command #!/bin/bash CMD file1 file2 file3 CMD -a - b -c file1 file2 file3 file4 CMD -d arg1 -e arg2 user1 ... .... Part III: (11 Marks) For each of the following programs you 1. Create a hello world program. Try different integer values as the return value from main.. Steps (2 marks) a. Create a new .c file using vim b. Type in PROG. If this doesnt generate code either ask for assistance or review the supplied reading on .vimrc. c. In between the { } & before t return statement type PR. This generates an fprintf. d. Use F3 to compile and F4 to run. Try different positive and negative integers as a return value. (If the return value is zero vim is silent.). Write up some representative test cases that you tried including negative numbers. e. Based on your experiments, determine the minimum and maximum value that can be returned by main? Recalling that there are 8 bits in a byte, how many bits are needed for this? (2 marks) 2. Run the program showArgs2 with 4 command line arguments of your own choosing, at least one of which is a flag and one of which is a non-flag argument. (3 marks) a. Record the command line that you used. b. From the program output, report the base address (the starting address) of argv and range of addresses used store the command line. c. Based on the output sketch using a pen or pencil a data structure diagram showing argv and each of the arguments as they are laid out in memory. Take a scan or a picture of your diagram and submit it as a separate file. 3. Exploring envp: (6 marks) a. Modify showEnvp.c so it reports envp addresses in the same style as showArgs2 displays argv addresses. Save a copy of the output in a file youll need to refer to it in part b. Provide a program listing, a status statement and 6-8 lines of output, but not all the output. (2) b. Inside your program use putenv to define one environment variable and setenv to redefine another. Where do these environment variables appear in the output? (2) c. Based on the program output sketch a data structure diagram for envp. You only need to include the first 3 environment variable values (2) Hand in a commented listing of your program, proof of testing and a status report. On your cover page, aside from your name, the course code, lab section and the assignment #. Make sure you include your student number. If I have to look it up to verify that you are doing the correct exercise I will deduct 2 marks. If you do the wrong exercise 2 more marks will be deducted.

Part II: 14 marks For this assignment you are assigned one of the commands listed below along with only the flags listed next to it. The # of your command matches the last 2 digits of your student number % 20, which means if your student # ends with 13, 33,53,73 or 93 (the tens digit is odd) you are assigned the man command, but if your # ends with 00, 20, 40, 60 or 80 (the tens digit is even) your command is vim. For this exercise the name of your source file name should be the name of the command, but in all caps so that you are not running the actual command, ie: CURL.C, not curl.c Each of the above is an actual Unix command. Review the man page information on the flags specified for the command you've been assigned. 0. vim -A-b-OnWindows -R -w logfile fileList 1. zip d e-i pattern -o -P password zipFileDestination filesToZip 2. cp -f -i -p mode -t startNum -s source(s) destination 3. curl -a -e url-h-m seconds -n urlList 4. egrep -A num -B num -C -1 V pattern fileList 5. file -b -f nameFile -F separator -h - fileList 6. gcc -g -O level -o outfile-S -E filelist 7. last -a -d of file -n num -R userList 8. killall ----s signalName -u user command List 9. In f - S suffix -t directory -v filelist 10. locate -- -d path in limit-S fileList 11. Ipr -Ctitle-h -P destination -m - fileList 12. mail- in -s subject -V-u user filelist 13. man E M path - P pager - command 14. php -a -c path -eT count file args 15. ping -a -A -c count -f -spacketSize destination 16. sed -e expression -I length-nr-5 fileList 17. sort -d k field.chars -r -t sep -u fileList 18. su -c command of 11-m-s shell user args 19. touch-C -d datech -m -r reffile fileList 20. tree -a -F-L level -2 -T title directoryList Implement a getopt loop in C that captures your assigned flags and then, after the loop, report on which flags have been set. Please note - you don't have to implement the actual command. All you have to do is demonstrate that you can capture the flags correctly. The steps to implement this are: a) Create a data structure FLAGS specific to your command. The field names in this data structure should reflect the purpose of the flag based its man page description. The data type of each flag should be appropriate as well - boolean, integer, double or char *. If there is no argument then it should be boolean, otherwise the datatype should be the determined from the man page description. (2 marks) b) Write a getopt loop with an option string that captures each of the flags. If a flag takes an argument the option is always followed by a colon. (4 marks) c) After the loop write a block of code that verifies that each of the flags and arguments were properly captured then lists the remaining non-flag arguments. Note - you can place debugging code inside the loop but verification must take place after the loop in case there are accidental side effects. (2 marks) d) A flag with an optional argument must have that argument directly attached to it and is specified with 2 colons after the flag character in the option string. Add an extra flag with an optional argument.ie: "xyp::z" will use -p123 not -p 123 (2 marks) e) Create a shell script to test your program. (4) i. Test with no flags and multiple trailing arguments. Verify that all FLAGS variables are set to their default. ii. Test with only the flags that do not take an argument. iii. Test with the flags that do take an argument. iv. Test with all flags in a random order. V. Test with a mix of 3 flags chosen randomly in a random order. vi. Write a status statement indicating whether or not your program worked. If you uncovered a bug, explain what it is. Your shell script will look something like this, but reflect the proper usage of your command #!/bin/bash CMD file1 file2 file3 CMD -a -b -c file1 file2 file3 file4 CMD -d argi -e arg2 user1 ... Part III: (11 Marks) For each of the following programs you 1. Create a "hello world" program. Try different integer values as the return value from main.. Steps (2 marks) a. Create a new .c file using vim b. Type in PROG. If this doesn't generate code either ask for assistance or review the supplied reading on vimrc. In between the{ } & before t return statement type PR. This generates an fprintf. d. Use F3 to compile and F4 to run. Try different positive and negative integers as a return value. (If the return value is zero vim is silent.). Write up some representative test cases that you tried including negative numbers. e. Based on your experiments, determine the minimum and maximum value that can be returned by main? Recalling that there are 8 bits in a byte, how many bits are needed for this? (2 marks) C. 2. Run the program showArgs2 with 4 command line arguments of your own choosing, at least one of which is a flag and one of which is a non-flag argument. (3 marks) a. Record the command line that you used. b. From the program output, report the base address (the starting address) of argv and range of addresses used store the command line. C. Based on the output sketch using a pen or pencil a data structure diagram showing argv and each of the arguments as they are laid out in memory. Take a scan or a picture of your diagram and submit it as a separate file. 3. Exploring envp: (6 marks) a. Modify showEnvp.c so it reports envp addresses in the same style as showArgs2 displays argv addresses. Save a copy of the output in a file - you'll need to refer to it in part b. Provide a program listing, a status statement and 6-8 lines of output, but not all the output. (2) b. Inside your program use putenv to define one environment variable and setenv to redefine another. Where do these environment variables appear in the output? (2) C. Based on the program output sketch a data structure diagram for envp. You only need to include the first 3 environment variable values (2) Hand in a commented listing of your program, proof of testing and a status report. On your cover page, aside from your name, the course code, lab section and the assignment #. Make sure you include your student number. If I have to look it up to verify that you are doing the correct exercise I will deduct 2 marks. If you do the wrong exercise 2 more marks will be deducted. Part II: 14 marks For this assignment you are assigned one of the commands listed below along with only the flags listed next to it. The # of your command matches the last 2 digits of your student number % 20, which means if your student # ends with 13, 33,53,73 or 93 (the tens digit is odd) you are assigned the man command, but if your # ends with 00, 20, 40, 60 or 80 (the tens digit is even) your command is vim. For this exercise the name of your source file name should be the name of the command, but in all caps so that you are not running the actual command, ie: CURL.C, not curl.c Each of the above is an actual Unix command. Review the man page information on the flags specified for the command you've been assigned. 0. vim -A-b-OnWindows -R -w logfile fileList 1. zip d e-i pattern -o -P password zipFileDestination filesToZip 2. cp -f -i -p mode -t startNum -s source(s) destination 3. curl -a -e url-h-m seconds -n urlList 4. egrep -A num -B num -C -1 V pattern fileList 5. file -b -f nameFile -F separator -h - fileList 6. gcc -g -O level -o outfile-S -E filelist 7. last -a -d of file -n num -R userList 8. killall ----s signalName -u user command List 9. In f - S suffix -t directory -v filelist 10. locate -- -d path in limit-S fileList 11. Ipr -Ctitle-h -P destination -m - fileList 12. mail- in -s subject -V-u user filelist 13. man E M path - P pager - command 14. php -a -c path -eT count file args 15. ping -a -A -c count -f -spacketSize destination 16. sed -e expression -I length-nr-5 fileList 17. sort -d k field.chars -r -t sep -u fileList 18. su -c command of 11-m-s shell user args 19. touch-C -d datech -m -r reffile fileList 20. tree -a -F-L level -2 -T title directoryList Implement a getopt loop in C that captures your assigned flags and then, after the loop, report on which flags have been set. Please note - you don't have to implement the actual command. All you have to do is demonstrate that you can capture the flags correctly. The steps to implement this are: a) Create a data structure FLAGS specific to your command. The field names in this data structure should reflect the purpose of the flag based its man page description. The data type of each flag should be appropriate as well - boolean, integer, double or char *. If there is no argument then it should be boolean, otherwise the datatype should be the determined from the man page description. (2 marks) b) Write a getopt loop with an option string that captures each of the flags. If a flag takes an argument the option is always followed by a colon. (4 marks) c) After the loop write a block of code that verifies that each of the flags and arguments were properly captured then lists the remaining non-flag arguments. Note - you can place debugging code inside the loop but verification must take place after the loop in case there are accidental side effects. (2 marks) d) A flag with an optional argument must have that argument directly attached to it and is specified with 2 colons after the flag character in the option string. Add an extra flag with an optional argument.ie: "xyp::z" will use -p123 not -p 123 (2 marks) e) Create a shell script to test your program. (4) i. Test with no flags and multiple trailing arguments. Verify that all FLAGS variables are set to their default. ii. Test with only the flags that do not take an argument. iii. Test with the flags that do take an argument. iv. Test with all flags in a random order. V. Test with a mix of 3 flags chosen randomly in a random order. vi. Write a status statement indicating whether or not your program worked. If you uncovered a bug, explain what it is. Your shell script will look something like this, but reflect the proper usage of your command #!/bin/bash CMD file1 file2 file3 CMD -a -b -c file1 file2 file3 file4 CMD -d argi -e arg2 user1 ... Part III: (11 Marks) For each of the following programs you 1. Create a "hello world" program. Try different integer values as the return value from main.. Steps (2 marks) a. Create a new .c file using vim b. Type in PROG. If this doesn't generate code either ask for assistance or review the supplied reading on vimrc. In between the{ } & before t return statement type PR. This generates an fprintf. d. Use F3 to compile and F4 to run. Try different positive and negative integers as a return value. (If the return value is zero vim is silent.). Write up some representative test cases that you tried including negative numbers. e. Based on your experiments, determine the minimum and maximum value that can be returned by main? Recalling that there are 8 bits in a byte, how many bits are needed for this? (2 marks) C. 2. Run the program showArgs2 with 4 command line arguments of your own choosing, at least one of which is a flag and one of which is a non-flag argument. (3 marks) a. Record the command line that you used. b. From the program output, report the base address (the starting address) of argv and range of addresses used store the command line. C. Based on the output sketch using a pen or pencil a data structure diagram showing argv and each of the arguments as they are laid out in memory. Take a scan or a picture of your diagram and submit it as a separate file. 3. Exploring envp: (6 marks) a. Modify showEnvp.c so it reports envp addresses in the same style as showArgs2 displays argv addresses. Save a copy of the output in a file - you'll need to refer to it in part b. Provide a program listing, a status statement and 6-8 lines of output, but not all the output. (2) b. Inside your program use putenv to define one environment variable and setenv to redefine another. Where do these environment variables appear in the output? (2) C. Based on the program output sketch a data structure diagram for envp. You only need to include the first 3 environment variable values (2) Hand in a commented listing of your program, proof of testing and a status report. On your cover page, aside from your name, the course code, lab section and the assignment #. Make sure you include your student number. If I have to look it up to verify that you are doing the correct exercise I will deduct 2 marks. If you do the wrong exercise 2 more marks will be deducted

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions

Question

Make efficient use of your practice time?

Answered: 1 week ago