 Hello everyone, myself Mr. F. R. Syed. I work as an assistant professor in the department of computer science and engineering at Walsh and institute of technology. So, I will put the topic for my today's lecture is handling signals in Unix system. Now, at the end of the session the students will be able to describe the handling of the signals in Unix system. Let us first see what is a signal in Unix system. Signals inform the processes of a synchronous events. Now, processes may send each other signals. Now, those signals could be sent either with the kill system call or the kernel may sometimes send signals internally. Now, there are a total of 19 signals in the system 5 relates to of Unix system and these signals are categorized. So, let us see those categories. The first one is some of the signals may be related to the process termination like those signals which are sent in case a process exists or signals send with the death of child parameter. Next category is there are some signals that are related to process induced exceptions like a process may try to access any address that is outside its virtual address space or we can also have a process that is trying to write on a memory that is dedicated as read only means no such write operation could be performed on that memory part. Also a condition could be like execution of any privileged instruction or in case any hardware errors occur. So, signals related to such events are coming under this category. The next category is the signals that are related to some kind of unrecoverable conditions during a system call like conditions as you can see as an example running out of system resources. The next category is there could be some signals for tracing the execution of a process. We have the next category there could be some signals that could arise due to unexpected error conditions. Now, what could be the error conditions? We will see some examples. The first one is making a non-existent system call. I mean a system call that actually does not exist if such kind of a system call is executed such kind of signals could arise. The next such condition is as we know a pipe does require a reader and a writer process associated with it. So, a condition like writing a pipe that has no reader process. So, that is another an error condition. The next type is using an illegal reference value for LC system call. The next category is signals originating from the processes in user mode like when an alarm signal is to be sent after a period of time or some arbitrary signals are to be sent to each other with the kill system call. Next is signals related to terminal interaction like if a user hangs up the terminal. So, signals could arise at that time or signals that could arise when the user presses break or delete keys on the terminal keyboard. Now, this is the process state diagram and we are going to see over here how the signals are going to be checked and handled. Now, there are two possibilities where the signals are checked and handled. Now, these are the two possibilities. The kernel checks for the receipt of a signal only when a process is about to return from kernel to user mode or when it enters or leaves the sleep state. So, this is indicated in this diagram over here when from kernel to user mode and moving between sleep and wake state. So, there is no instant effect on the process running in the kernel mode and a process never executes in user mode before handling the outstanding signals. Now, next we see an algorithm for recognizing a signal the name of the algorithm is ISSIGS signal. So, it returns as output true if the process received signals that it does not ignore otherwise it returns false. So, while the received signal field in the process table entry is not 0 it will find a signal number sent to the process and if the signal indicates it is a death of child and if ignoring death of child signal that means, if the death of child signal is to be ignored in that case it frees the process table entries of the zombie children otherwise if the death of child signal is to be catched then it returns true. Now, this is when the signal is for death of child otherwise if it is not going to ignore the signal meaning the signal will not be ignored in that case also it returns true and at the end turns of the signal bit in the received signal field in the process table. So, now the students are expected to think and write the answer to the following question what are the different ways in which a process responds to a signal. Now, pause the video and write your answer. Okay now let us see the answer to the question what are the different ways in which a process responds to a signal? The first way in which the process responds to a signal is it either ignores the signal or second one it will handle the signal and third one it will perform some default action. So, these are the three ways in which the process may respond to the signal. Now, let us see the topic of handling of signal. Now, there are three cases for handling signals the first one is the process may exit on receiving a signal that is the process may come to a termination when a signal is received second one it will ignore the signal meaning it does nothing when a signal occurs and third one it may execute a particular user function on receiving a signal. Now, this is a syntax for the signal system call old function equal to signal into bracket two parameters signal comma function where signum is the signal number of the signal for which the procedure is to be done function is the address of the user defined function that is to be executed on receiving the signal indicated by signum and the return value old function was the value of function for the most recent call to signal for signum. The process can pass value 1 or 0 instead of the function address and the future occurrences of signal are ignored if the parameter value is 1. Now, this is the algorithm for handling of the signals algorithm PSIG. So, the first thing that it does is gets the signal number set in the process table entry and then clears that signal number from the process table entry. If the user had called signal system call to ignore the signal then it returns otherwise if the user specified function to handle the signal then it gets the user virtual address of the signal catcher that is stored in the user area. Then it clears the u area entry that stored the address of the signal catcher and then it modifies the user level context and the system level context and ultimate late returns. If the signal is such that the system should dump core image of the process then in that case it creates a file named as core in the current directory and then writes the contents of the user level context to the file named as core and ultimately it invokes the exit algorithm immediately. Now, the kernel first determines the signal type and turns off the appropriate signal bit in the process table entry as we have seen in the algorithm and if the signal handling function is set to default value the kernel will dump a core image of process for certain type of signals before exiting. Now, the kernel dumps core for signals when something is wrong with the process like either the process is executed an illegal instruction or has accessed any address that is outside its virtual address space. The kernel does not dump core for signals that do not imply a program error that is in case of receipt of an interrupt signal. The quit signal indices the core dump and the processes behave differently in different scenarios like if it receives a signal to be ignored it behaves as if nothing has happened and if it receives a signal that it has previously decided to catch in that case it calls the user function for handling the signal. This is the reference used for the video lecture. Thank you.