Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4) If you changed the kernel so it didn\'t generate SIGCHLD signals, how would t

ID: 3587947 • Letter: 4

Question

4) If you changed the kernel so it didn't generate SIGCHLD signals, how would the behavior of userspace programs change? 10) What system calls are used to list all the files in a directory? What are the library calls that are normally used to make those system calls? 12) What happens to an in-progress system call when a process receives a signal? 6)Does a program make a system call to get the value of an environment variable? Why? 13) Describe how you could add input redirection for external programs

Explanation / Answer

4)

If a child process has a PID in the process table remaining and the execution of the child process is finished, then this type of process is called as zombie process. The SIGCHLD signal is used to reap the zombie processes.

The zombie process can be killed by using SIGCHLD signal with a waitpid. If the kernel does not generate the signal SIGCHLD, thewn the zombie processes are not killed and it lead to increase more number of zombie processes which further can fill the process table.

If the child process of the userspace programs terminate, then the userspace programs will not be changed.

The userspace programs will remain as zombie process and the return value of the child process cannot be seen by the userspace programs until and unless these programs generates the wait() calls outside of a signal handler.

10)

The system calls to list the files in a directory are as follows:

·       The system call open is used to open a directory. The library call which is used to make this call is opendir.

·       The system call getdents is used to read the entries in a directory. The library call which is used to make the system call to read the entries is readdir.

·       The system call close is used to close the file descriptor of the directory. The library call which is used to make the system call to close the directory’s file descriptor is closedir.

12)

The signal handling is an important operation during process execution. There may be a chance such that a signal received by an in-process system call can interrupt the execution of the process.

Signal handling is sometimes considered vulnerable because it may cause race condition. A signal which is received by a currently running system call will interrupt the system call and cancels the execution of the system call by default.

The system call interrupted by a signal can be restarted by a signal SA_RESTART which will restart the execution of the system call.

6)

An environment variable can be read by passing it to the main function as its third argument. The environment variable can be read at run time in C.

The environment variable resides in the memory of the process. The environment variables can be accessed in the same manner in which a data structure residing in the memory of a process is accessed.

Hence, a program does not make a system call to get the value of an environment variable.

13)

The input/output is redirected from a file in the shell script. For example:

echo “a line of text” > File

The above command is creating a file named as File and inserts the message written in quotes into the file.

The symbol “>” is used to redirect the input to a file. The file can be appended with another message using the following command:

echo “one more line” >> File

The above command will append the text written in the quotes to the file named as File. The symbol “>>” is used to append the text tot a file.

The input redirection can be added for external programs as follows:

·       A file should be open for input redirection, if the file is not open, then first open the file.

·       The file descriptor is used for input redirection, copy the file descriptor using dup2.

·       The filename and sign “<” should be removed from the argument list.

·       Use execve to execute the program.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote