Operating Systems 2018F Lecture 11

From Soma-notes
Jump to navigation Jump to search

Video

Video from the lecture given on October 10, 2018 is now available.

Notes

  • Today:
    • Discussing Assignment Solutions
  • From Assignment 2:
    • The first two questions are related, however, the first question requires you make a hard link. A hard link means that both associations point to the same inodes. A hard link just creates a separate differently named association that accesses the same file. (Hard links only work within a single file system)
    • The second question involves creating a symbolic link. Running lstat() returns the inode relating to the link instead of to the file.
    • Question 3 – statbuf has the user id and group id stored. The username and group name can be looked up via the password file using getgrgrid() and getpwuid().
    • Question 4 – Trying to write to the file produces a SEGFAULT. The reason for this is that you do not have access to write to the file as it is readonly. A SEGFAULT will be produced any time an attempt is made to access private memory. PROT_READ would allow you to have access however.
    • Question 6 – Placing an exit command within the if statement at line 215 will permanently stop the consumer.
    • Question 7 – malloc uses private memory whereas mmap does not. Replacing mmap with malloc means the producer and consumer will be accessing separate memory and the consumer will never consume.
    • Qestion 8 – The kill signals are interrupting the sleep commands. Removing the kill signals means the sleeps will never be interrupted and there will be a delay every time.
    • Question 9 – You are not supposed to be able to predict the output of /dev/random. Technically you can if you can figure out the inputs. If the input was compromised then the “random” numbers could be compromised.
    • Question 10 – sem_wait() and sem_post() do not produce system calls. They do require special CPU instructions, but do not need to make system calls.
  • Why use goto?
    • In C, there isn’t built in error handling such as try catch, so goto can be used for error handling since they stay in method scope.
    • Linux kernel code uses goto in this manner.
  • Assignment 1
    • Question 1 – When a process is run in the foreground the shell will wait for the program to terminate, but when a process is run in the background the shell will not wait. This means the default is to run background processes and extra information is required to monitor processes in the foreground.
    • Question 2 – Signals are not received by system calls.
    • Question 4 – Removing the wait() command will prevent the child processes from being properly terminated and so they will accumulate as zombie processes.
    • Question 9 – execve does not close file descriptors. If it did you couldn’t have stdIn, stdError. The file descriptors for stdOut is 0, stdIn is 1, and stdError is 2. File descriptors are what are returned when a file is opened for the purposes of reading and writing to the file. Therefore, every open file will have a file descriptor.
    • Question 10 – An in-progress system call is interrupted upon receiving a signal. It can possibly be restarted later.
    • Question 11 – plist is doing an ls command on /proc. This specifically shows “comm” files which most other directories will not contain. Thus giving different directories to plist will not give much back.
    • Question 12 – Input the file through $echo FileToDirect > shell3000. Use dup2 to retrieve the file descriptor and then run it using execve.