CS计算机代考程序代写 interpreter CSE 2431 HOMEWORK 1 SU 2021

CSE 2431 HOMEWORK 1 SU 2021
Online Submission to Carmen Due: Thursday May 20, 2021 at 11:30 pm. Note: You should submit your homework electronically on Carmen as a pdf file (see below); ALSO, you should retain the C source code files and executables which the instructions direct you to create and compile or run, because you may be asked to show them to the instructor or graders.
NOTE that labs are due at 11:30pm on the due date. There is a one half hour “grace
period,”so as long as you submit before midnight, your lab will be counted as on time.
HOWEVER, you should not wait till after 11:30 to submit; your goal should be to submit by
11:30 AT THE ABSOLUTE LATEST (but even this is unwise; aim to submit well in advance
of the deadline, sometime early in the evening)! If you submit after midnight, your lab will be
counted and graded as late, and we will not accept any “excuses” for submitting later
than midnight, because the deadline is 11:30 pm.
The goal of CSE 2431 homework is to give students an opportunity to understand the Unix/Linux fork() system call, which is used to create new processes, and also to give students experience with the stdlinux system along with the command line interpreter, as well as introducing students to forking processes.
All answers for the homework will be submitted to Carmen in a pdf file by the due date specified above. You should not discuss the homework with other students; the homework must be the student’s own individual work. You may use Piazza to post any questions which you have; if you reveal what you think the correct answer to a question is, or may be, be sure to leave your post private. Guidelines for Piazza and communication are given on the Syllabus and on Piazza.
All homework answers must be typed, printed, and submitted electronically to Carmen in a pdf file.
On the CSE Linux System, under your home directory, create a directory cse2431 for Systems II. Create a directory/folder called hw1 using the command line interface. In that directory, you will download several C source code files from Carmen, and create several other C source code files, with code as described below.
After creating your cse2431/hw1 folder on stdlinux, start a firefox web browser, by executing the following command:
$ firefox https://carmen.osu.edu/#
When the web browser starts, log in, and go to the Homework folder for CSE 2431 in the Files
area.
Download the forktest1.c file to your cse2431/hw1 folder on stdlinux. Download the forktest2.c file to your cse2431/hw1 folder on stdlinux.
1

Download the forktest3.c file to your cse2431/hw1 folder on stdlinux. Download the forktest4.c file to your cse2431/hw1 folder on stdlinux.
IMPORTANT: When you answer the questions below, you should put your answers in a file which you create with whichever word processor you prefer (not on stdlinux, but on your system), and when you have all your answers, export your file as a pdf. Also be sure that you read and understand the file Linux fork.pdf on Carmen in the HW folder.
ALSO IMPORTANT: When you answer the questions, make use of concepts discussed in class, such as processes, the address spaces of processes, parent and child processes, pid numbers, the relationship between pids for parent and child processes, and the fork system call which is used to create processes in Linux. Finally, consider the behavior of the OS scheduler, which we have not discussed in great detail, but its general behavior has been described. You can assume that the server has a single-core CPU, so only one process at a time can be running, but there may be multiple processes in execution (processes which have been created, but have not yet terminated). Label the answers as the corresponding question is labeled, so that it is clear which of your answers is responding to each question.
Note: Linux commands are shown with the $ shell prompt. If you have a different prompt in stdlinux, the commands will still be identical, and they will work the same way.
NOW DO THIS: Compile forktest1.c as follows: $gcc forktest1.c -o forktest1
Run the program from the directory where you compiled it: $forktest1
Question 1. How many processes are created when the program runs (include in your count the process created to run the program when you execute it from the command line on stdlinux). Describe briefly what is done by the process(es); refer to parent and child process when you describe what the processes do..
a) Are the results what you expected? Explain.
b) Run the program various times, until the sequence of lines which print values (what is output as “value”) is different. How many times did you have to run the program to get a different sequence?
c) Now explain, as clearly as you can, in terms which mention the CPU scheduler and I/O system calls, why the sequence can vary for different runs of the program.
NOW DO THIS: Compile forktest2.c as follows: $gcc forktest2.c -o forktest2
Run the program:
2

$forktest2
Question 2. How many processes are created when the program runs (include in your count the process created to run the program when you execute it from the command line on stdlinux)?
a) What value or values is/are output by the program for the variable num? Answer in terms of parent and child processes.
b) The value of num is changed from the initial value by the program code. Is this change shown whenever the value of num is printed in the output? Answer in terms of parent and child processes.
c) Explain why the change in num is or is not reflected by the output (depending on what you answered for Question b) above). Give your explanation in terms of parent and child processes.
NOW DO THIS: Compile forktest3.c as follows: $gcc forktest3.c -o forktest3
Run the program: $forktest3
Question 3. How many processes are created when the program runs (include in your count the process created to run the program when you execute it from the command line on stdlinux)?
a) What value or values is/are output by the program for the variable num? Answer in terms of parent and child processes.
b) The value of num is changed from the initial value by the program code. Is this change shown whenever the value of num is printed in the output? Answer in terms of parent and child processes.
c) Explain why the change in num is or is not reflected by the output (depending on what you answered for Question b) above). Give your explanation in terms of parent and child processes.
NOW DO THIS: Compile forktest4.c as follows: $ gcc forktest4.c -o forktest4
Run the program: $forktest4
Question 4. How many processes are created when the program runs (include in your count the process created to run the program when you execute it from the command line on stdlinux)? [DO NOT just count pids! You need to justify this answer with your explanation for part a) below.]
3

a) Explain the parent-child relationships between the processes created when the program executes. You can make a diagram if it is helpful (but it is not required), but you need to give a verbal (word-based) description of the relationships. Explain, as clearly as possible (and clarity counts!) how the execution of the C code in forktest4.c results in the creation of processes which have the parent-child relationships you identify. If the terms are needed to in order to answer, for a child of a child, you can use the term grandchild, and for a child of a grandchild, you can use the term great- grandchild.
Question 5. What do you think the point was of entering and running these programs as processes? What did you learn?
Question 6. What is a pid? How is a pid useful? It appears that a child process has two pids associated with it (Note: This does not mean a child process has two pids, but rather, it has two pids associated with it); what are the values of the two pids? Why are there two?
Question 7. Look at the online manual page for ps, that is, do a ‘man ps’. What does ps do? Enter and run the commands ‘ps’, ‘ps –f’’, and ‘ps –af’. What are the differences?
Question 8. Look at the online manual page for kill. What does kill do? How might it be useful? How does it relate to the ps command?
Directions for this part: Give a one or two sentence description, in your own words, of each of the following system calls:
Question 9. fork Question 10. getpid Question 11. getppid Question 12. wait
Type your answers to the questions above in a document with a word processor, and export the document to a pdf file called hw1.pdf; to submit the file hw1.pdf to Carmen, log in, and select HW1 under Assignments.
Homework not submitted by the deadline on the due date but within 24 hours will be assessed a 25% late penalty of the grade for the whole homework assignment; homework is not accepted after that time.
4