lab4-report-template

pdf

School

University of Iowa *

*We aren’t endorsed by this school

Course

036:01

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

pdf

Pages

8

Uploaded by JohnDeckland20

Report
Whenm pressing CTRL-C during the program, the my_routine function is called even though the process is in an infinite loop. When pressing CTRL-C in a program, it sends a SIGINT signal to the running process in the terminal and this tells the process to stop running and terminate. This program redefines the SIGINT value to call a function which printed to the terminal though so the actual program did not stop. In this lab, we learned about signals and the capabilities of utilizing piping alongside these signals. We experimented with the signal statements that interrupt processes and how to manipulate them to call other functions. In addition we learned about how servers and clients work with shared memories while still using signals to communicate. Name: Eric Christensen Section: 2 University ID: 057392383 Lab 4 Report Summary (10pts): Lab Questions: 3.1: 6 pts After reading through the man page on signals and studying the code, what happens in this program when you type CTRL-C? Why?
The program terminated because the new SIGINT was not defined as it previously was so it defaulted to stopping the program. The program now does not stop when pressing CTRL-C because of this re-definition of the signal. Since you redefined the signal SIGQUIT to call the method, it no longer does it s defaulted process of killing the program but instead calls the function. 3 pts Omit the signal(...) statement in main. Recompile and run the program. Type CTRL-C. Why did the program terminate? 3 pts In main, replace the signal( ) statement with signal(SIGINT, SIG_IGN) . Recompile, and run the program then type CTRL-C. What’s happening now? 3 pts The signal sent when CTRL-\ is pressed is SIGQUIT. Replace the signal() statement with signal(SIGQUIT, my_routine) and run the program. Type CTRL-\. Why can't you kill the process with CTRL-\ now?
CTRL-C is 2 and CTRL-\ is 3. The user input is what causes the signal to be sent and the background terminal has a signal handler built in which receives the signal and determines what to do with it. 3.2: 5pts What are the integer values of the two signals? What causes each signal to be sent? 3.3: 10 pts Include your source code
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
The signal statement should come first because if you don t have your signal defined, when the divide by zero exception comes, it the signal won t have your definenition and instead will go to it s default process. Signal definition must come first. This program takes two inputs and uses signals to set the return statement and time until the statement is printed through an alarm. The parameters are the time before the signal is sent to the alarm and the message to be sent to the terminal. The function alarm takes a time input and waits a designated amount of time before sending a signal to the process after that time has ended. This is used to trigger a print statement. 5 pts Explain which line should come first to trigger your signal handler: the signal() statement or the division-by-zero statement? Explain why. 3.4: 4pts What are the parameters input to this program, and how do they affect the program? 6pts What does the function alarm do?? Mention how signals are involved. 3.5: 2pts Include the output from the program.
There are 2 processes running of this program (I accidentally had 2 instances of the program running thus there are 4 processes of mr3 running) Two processes received signals Process 24334 sent the message of Return val from fork : 0 and Process 24333 sent the message of Return val from fork : 24334 Two processes are running if ret > 0 then the program is the parent process, but otherwise it is the child. 2pt How many processes are running? 3pts Identify which process sent each message. 3pts How many processes received signals? 3.6: 2pts How many processes are running? Which is which (refer to the if/else block)?
The processes use shmget with their keys to locate the same memory space There is a sleep statement to make sure the message is able to go through the pipe. A better way would be to use a wait statement to ensure the message went through. If both are trying to write or one is reading while one is writing then there could be concurrency issues. IE they don t lock and unlock Without the server running, I got Permission denied . This is because the server was not running to verify the key of the client so it the client did not have the permissions to read.get The parent process writes the message to the pipe with the write(p[1] ) then the message is sent to the variable inbuff with the child process through the read from the pipe and then the child process prints it out. 6pts Trace the steps the message takes before printing to the screen, from the array msg to the array inbuff, and identify which process is doing each step. 2pts Why is there a sleep statement? What would be a better statement to use instead of sleep (Refer to lab 2)? 3.7: 3pts How do the separate processes locate the same memory space? 3pts There is a major flaw in these programs, what is it? (Hint: Think about the concerns we had with threads) 3pts Now run the client without the server. What do you observe? Why? 6pts Now add the following two lines to the server program just before the exit at the end of main: shmdt(shm) shmctl(shmid, IPC_RMID, 0)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
A process that tries to read from a message queue that has no messages will be blocked until a message arrives on the queue or a signal interrupts if the process is using a blocking read call These messages can be destroyed when the storage is no longer needed or when a particular process shurts down and it is done by using the IPC_RMID command Without the server running, I got shmget failed: No such file or directory and with the server running, I got The Message read: abcdefghijklmnop .. along with Client done reading memory . These two lines deleted the shared memory once the server process ended which explains why the client s response was not found instead of permission denied. Message queues can hold a max size of 16384 bytes per message Recompile the server. Run the server and client together again. Now run the client without the server. What do you observe? What did the two added lines do? 3.8: 2pts Message queues allow for programs to synchronize their operations as well as transfer data. How much data can be sent in a single message using this mechanism? 2 pts What will happen to a process that tries to read from a message queue that has no messages (hint: there is more than one possibility)? 3pt Both Message Queues and Shared Memory create semi-permanent structures that are owned by the operating system (not owned by an individual process). Although not permanent like a file, they can remain on the system after a process exits. Describe how and when these structures can be destroyed. 3pt Are the semaphores in Linux general or binary? Describe in brief how to acquire and initialize them.
The semaphores in linux can be either binary or general. It just depends on what you re using it for. To acquire them you can use semget() to acquire a semaphore and you can use semctl to manipulate a semaphore.