Q: Is there a tutorial tomorrow? (04-08-2023, Friday)
[VJS]: Nope, we will be having the tutorial on Saturday (05-08-2023) as announced on moodle.
Okay, I might have missed that. Thank you.
Q: For projects in this course, will Xv6 be enough or do we need to have any other particular OS?
[DJ]: xv6 will be enough for this course. Linux is preferred for OS and xv6 is run using qemu over that.
Q: is xv6 recommended or is pop os good enough
[DJ]: xv6 is not an OS that you will be using to run your system. It's a toy os that you will be editing on top of another OS. You can have your usual OS (Ubuntu, Pop OS etc.) running and run xv6 on top of that. You are not supposed to run it as a default OS on your system.
Q: Do we require GUI with xv6 (since I am installing it on WSL)?
[DJ] You don't need GUI with xv6, it's purely terminal based.
q. what will happen if parent process completes before child process.?
[DJ] When a parent process terminates before it's child process, the kernel marks the child processes as "orphans" and re-parenting happens. These orphan processes, now become children of the init process (pid = 1). The init process calls wait on these processes periodically so that they can exit normally after releasing the resources that are allotted to them.
q. can you explain more on pid use and working in class
[VJS] I do not know if it will be possible to do so in the class, but we will try to cover it a bit in detail in one of the tutorial.
Q: Sir, if possible, is there anyway you can consider changing your office hour timings? (Most of UG2 and UG3-CLD have class from 11-12am on friday)
[VJS] Will get back to you, have informed sir.
[KV] Let me check this. One possibility is to move this to Wednesday morning slot. I shall check with others in the class about this
Q: So, during the exec() system call, the process which was running is transformed into an entirely new process with new parameters like memory space, stack, heap,etc. Isn't this a bit inefficient since the old memory addresses are not freed and they get wasted??
[VJS] From my understanding, transformed might not be the most appropriate wording. What happens is the existing process gets replaced with the new process that is called through exec. all those new parameters, memory space stack etc, are more or less in a sense overwritten. If it still feels ineffecient, whenever a process does have to close all of it's memory and stuff need to be de-allocated (destroyed). If I didn't exactly answer your question please feel free to rephrase.
Q: So, in continuation of the above question, there is no new resource allocation happening. Just all the parameters are reset to initial conditions. Is this correct?
[DJ] : Resource allocation happens if required, all the memory of a process is reclaimed when an exec call happens.
- [q ] Q:Sir when I execute multiple process let's say they are p1 and p2 when p1 is executing for how does os prevents it overwrite the register of p2? and how does kernel stack is helpful?
[DJ] : I believe this will be covered later in class but it's basically the case that a process is not allowed to access the memory allocated to another process. As far as registers are considered, they are saved during context switch so assuming a one processor system, when p1 is running, the registers will have values for p1, hence it can only edit that.
Q: With respect to fork(), can every parent only have 1 child? or if there can be multiple, does the PID of a parent keep changing to the latest child it creates?
[KV] Every parent can have multople child. There is no limitation per se on the number of child a parent process can have. The PID of a proces will not change based on the child process it creates. When a fork() is called, the child process is created and it will get a unique PID. This process can inturn become parent for other processes as well.
Q: Is it okay to copy-paste stack overflow codes or codes from gfg (codes like reversing a string or how to remove a directory)?
[DJ] : This is subjective, it depends on how much copy pasting you do. I can't say it's allowed in all cases because people will use it to copy larger piece of codes but if it's a couple lines of code that you understand, it should not cause any issues. We will be running Moss on submissions so if you copy too much, you might get in trouble.
Q: In Round Robin Scheduling technique, the OS executes processes one by one for a particular time interval. Suppose that there are n (assume n is a large number) number of processes that are to be executed, then will the OS execute each one of them (which increases the turnaround time as well as the overhead for context switching) or does it select a few processes based on some pre-determined priority and does round robin scheduling on those select processes?
[DJ] : If all of them are loaded in the ready queue, then OS will execute all of them. It's the job of Long Term Scheduler to decide how many processes should be brought in the ready queue.
Q: So, everytime an interrupt occurs (like timer interrupt), it changes from user to kernel mode and control goes to OS, this in turn if needed does context switch? Does that also mean context switch can only occur in kernel mode or if there is a syscall for switch()?
[DJ] : Yes, context switch can only happen in kernel mode since you need unrestricted access to memory for accessing data of processes (to be saved and to be brought in). I don't understand what you meant by the part about switch. There is no system call as such for context switch because as far as the process is concerned, it has sole access to the processor and memory. Hence, it doesn't even know about the context switch happening.
Q: In context of pointers and fork, suppose in main function I have an integer variable (declared int a =5) and a pointer storing adress of a (int *p* = &a), I tried modifying the value of the integer stored at address p in the parent process but it didnt change in the child process. When i try to print the adress ( p ) in either its the same, how is the adress same in both child and parent processes but it stores a different value? (I tried to read on it online, it had something to do with COW mechanism, i.e the adress remains the same until a write on the page has been performed, but even after writing on the adress pointed by p, the adress remains same??).
[DJ] : This is because of memory virtualization and difference between virtual address and physical address. Read more here : https://stackoverflow.com/questions/33021639/what-happens-to-addresss-values-and-pointers-after-a-fork
Q. What happens when there are several zombie childrens? Is init() capable of waiting for all of them?
[DJ] : Yes, it can wait for multiple orphan processes. By the way, what you are asking is an orphan process and not a zombie process. Zombie processes are different (look it up)
Q. A successful call to exec never returns. This is very tough to digest, given how strict C compilers are about return statement. Please share some readable references about its implementation for clarity.
[DJ] : Since it is a system call, exec is able to ask OS so that it can go behind the C compiler and re-write the return address. Since the process image is updated, the return address and the stack is also updated. You can a bit about this here : https://pubs.opengroup.org/onlinepubs/7908799/xsh/exec.html#:~:text=The%20exec%20functions%20replace%20the,by%20the%20new%20process%20image. However, if you want it to understand more clearly, you will have to look at Linux source code. I believe this concept of re-writing the return address of a function will become more clear when doing xv6 Mini Projects in the near future.
Q. Are we supposed to work with Xv6 itself or just C prgramming works for the mini-projects ?
[DJ] : xv6 is written in C so both.
Q. Could you please explain in detail what exactly will happen when sleep 20 command will run in the background ?
[DJ] : Without getting into how sleep is implemented (you may understand more on this when doing xv6), it will simply do nothing. The sleep process will run in the background and have no effect on other processes (as it does not take any input/output whatsoever) and exit after it's sleep time is over. The main effect of sleep in foreground is to not let other processes run, while it has no other direct impact but since it's running in background it can't stop other processes from running. Hence, it only reduces to having no direct impact.
Q. Do we have to include <> these symbols before and after the hostname and system name while the terminal is running ?(mini project 1)
[DJ] : Yes, take the output in Mini Project document as the ground truth. Also, this is general doubts document, use the Mini Project - 1 doc to ask questions related to it.
Q. I am working on Linux, so whenever I open my original terminal, I get "username@sysName:~$". From here, if I do "ls" then it gives all typical folders with "Desktop" as one of them where I can actually find all other docs that I usually save. But when I try to get the current directory address in my C code, the address starts from "/home/username/Desktop/....so on". Now, my doubt is, does ~ represent "/home/username/" or only "/home" (according to the Linux terminal)? And also, do we have to include the $ after the whole address is over at the end?
[DJ] : A user's home directory is /home/username by default. You can use "echo $HOME" to check yours. The tilda (~) expansion is a feature of the shell and not the OS which is why you get the complete address /home/username/whatever/xyz as the OS is returning that.
Q: What reference textbook is recommended for the 'networks' part of the course?
[VJS] One of the suggested books is Computer Networks (5th Edition) Andrew S. Tanenbaum, David J. Wetherall, Prentice-Hall, 2013. It is already present on the website.
Q: What is the number inside the square brackets written infront of specifications? eg Specification 1 : Display Requirement [5], what is '5' ?
[VJS] Marks for that part. Also this is specific to MP1 at this point, Please keep doubts related to MP1 in the respective document.
Q: Does the directory structure have to strictly follow the boilerplates provided by github?
[DJ]: Yes, but if you just want to place some extra files, that should be fine.
Q: Does editing the directory structure/README.md affect the submission time?
[DJ]: Yes, don't edit now.
Q: If a project is submitted soon after intermediate deadline (without extension), say 1 hour later, does that count up as 1 day of extension used?
[DJ]: Yes, since it's late.
Q: Note that there are two types of register saves/restores that happen during this protocol. The first is when the timer interrupt occurs; in this case, the user registers of the running process are implicitly saved by the hardware, using the kernel stack of that process. The second is when the OS decides to switch from A to B; in this case, the kernel registers are explicitly saved by the software (i.e., the OS), but this time into memory in the process structure of the process. The latter action moves the system from running as if it just trapped into the kernel from A to as if it just trapped into the kernel from B. Can you please explain the meaning of the last line in this para?
Q: Hey could you explain how exactly the evaluations will be conducted? As per my understanding, everyones code at the end of the mini project will be a couple thousand lines of code. The assignment page and the doubts document specify some functions which are not allowed to be used. Will everyones code even be checked for usage of these functions? Will the eval consist of just checking input and output or will there actually be review of the code base? If yes, how will this happen in a timely manner that is fair to all students?
[DJ]: Please leave the headache regarding this to us and work on submitting the Mini Projects.
Q: Are recursion (as learnt before this course) and creation of a child process related?
[DJ]: Not really. A process forking, creates an entirely different process which runs in `parallel` with the parent process. Also, it's not necessary that the child process will return before the parent process. This makes it quite different from how recursion works (serially).
Q: How does pipe work in bash exactly?
1. ``sleep 5 | echo hello`` runs until the first command, sleep has executed.
2. ``base64 /dev/urandom | head -c 10`` terminates right after the second command has finished reading 10 bytes.
[DJ]: In Linux, commands that are being piped are actually executed parallely (rather than one by one). This is why if you run the first command, it prints hello right away as it runs parallely with sleep and then sleep is executed for 5 seconds. In this scenario, if sleep attempts to write to the pipe after echo hello finished being executed, SIGPIPE signal would have been sent to sleep, terminating it. However, sleep never attempts to write to the pipe even after echo hello is done executing.
However, this is not the case for the second command given. In this scenario, head -c 10 exits after reading 10 characters meaning the pipe is now without any readers. This causes SIGPIPE to be sent to /dev/urandom when it tries to write to the pipe and terminates it.
You can find more regarding this here : https://unix.stackexchange.com/questions/613848/how-does-head-stops-cat-in-following-command-cat-dev-urandom-head-c-10
Really nice doubt btw, keep it up!
Q: In miniproject 1, how should we continue the second part? Are we supposed to push to the same branch as before or to a new branch. Please clarify.
[DJ]: This has been mentioned on Moodle already.
Q: Is pipe() a valid system call for piping?
[DJ]: Yes.
Q: As sir mentioned in the class that modern OS use some sort of advanced paging technique for memory virtualization. But if I run a program and it leads to some sort of segmentation fault, does that mean modern machines support segmentation?
Q: How does the OS clean up/free the memory which was used by a process, after the process is finished?
Q: AI based operating system is not yet developed right ! Could anyone please tell how does *OpenAI Interpreter* work?. how does it get access to control the Operating system especially in case of windows and MacOS ? (about openAI interpreter : https://github.com/KillianLucas/open-interpreter.git)
Q: Is gaming of the TLB possible?
Q: In the lecture 9 of the OSN, it is written that the code grows positive and it is even written in the book but in the previous chapters of the book, it is written that the code is static and it is only heap and stack that are growing as the process is a running program and in the space allocated for the process, the code should not change. So, just wanted to confirm whether it was written out of convention that code and heap grow positive (essentially downward) while the stack does so in the opposite direction?
Q. From the same man page: "malloc() and related functions rejected sizes greater than PTRDIFF_MAX". What are PTRDIFF_MAX, MIN and why do they print to be -1 and 0?
Q. This program's output changes (slightly) every time I run it - https://github.com/remzi-arpacidusseau/ostep-code/blob/master/vm-intro/va.c . Is this the randomization referred here - https://www.win.tue.nl/~aeb/linux/hh/protection.html ? Is this like the static relocation, where the addresses are overwritten before the program is run. Which component does this exactly?
Q. Consider this program.
```
#include <stdio.h>
#include <stdlib.h>
int main()
{
int *A = (int *) malloc(100 * sizeof(int));
free(A);
//printf("%d\n", A[4]);
return 0;
}
```
- When I run this using valgrind, I get ``total heap usage: 1 allocs, 1 frees, 400 bytes allocated``.
- When I uncomment the third line and run it again, I now get: ``total heap usage: 2 allocs, 2 frees, 1,424 bytes allocated``
Please explain this difference.
Q. Consider a 32 bit address space with 4 KB pages. What will be the number of bits for offset? In this question, I just wanted to confirm that 4KB is the size of one page and not number of pages because if it is number of pages, then it should be counted for VPN but the opposite is there in both presentation and book?
Q: When the processes can share the page, then how does the problem of internal fragmentation come in paging?
Q: What is the penalty for submitting after the given late days?
Q: When spin locks are implemented using preemptive schedulers then how does it not guarantee fairness?