---
# System prepended metadata

title: Mini Project 2 Answers

---

1: I wasn't allowed to Sync fork due to some merge conflicts that I couldn't make sense of, is it fine if i delete the folder and use the official xv6-riscv MIT repo instead?
[VG] - Yes you are free to do that, just make sure to follow the submission format.

2: Is picking up code from online sources allowed? Any citation rules?
[VG] - No, you are not allowed to do that.

3: If I tell AI the exact logic and working of the code but tell it to write it, cuz I dont wanna manually write 20-30 lines of simple if else conditionals or for loops, does that count as LLM-Generated code?
[VG] - Yes it does.

4: In WireShark task 1.1, its mentioned that the user should be able to select an interface to monitor, and the example output was provided. but in task 1.2, its mentioned "For this phase, you only need to implement the first option."
so do we need to show all those 10 options given in the task 1.1 example ouput or not, or just show wlan0
as the only option of interface to select?
[DM] - What I meant by
> For this phase, you only need to implement the first option.

is that as task 1.2, you only need to implement monitor all packets while option 2 and 3 that is monitoring with filters and inspecting sesions are to be implemented later. So Task 1.1 is ability to scan for all network interfaces, and task 1.2 is to be able to monitor all packets on any of the available interfaces which you showed in task 1.1

5: In Part C, should the input be read from a file or via CLI? Since it is not mentioned in the submission Format.
[SG] CLI is fine , anyways you can use redirections(<) to send input from a file

6: In Part B, task 2.3, can we assume no extension header handling needed for obtaining L4 when IPv6 is the protocol?
[DM] - Yes, no need handle extension headers - you can skip them. But you will still need to display L4 TCP/UDP information for IPv6 too.

7: Can we make Part C modular with .h files and Makefile? Or one single .c file without a Makefile. How is the input for part C taken. should output be redirected somewhere for checking?
[SG]making your code modular is always nice :)

8: in phase 2, what if we do ctrl c while we are in the main menu?
[DM] - It stays in the main menu.

9: what should be the error message if there are no interfaces found?
[DM] - I doubt there'll be any modern device with no interfaces present as all of them atleast have local loopback, but put any appropriate error messsage you feel like.

10: just to confirm, for all the interface option if selected the same menu option is provided right? or only for option 1?
[DM] - Same menu options for all interfaces.

11: In part C, will inputs be sorted according to timestamp?
[SG] yes

12: In part C, it is mentioned that a customer cannot enter the bakery if it is at capacity, but there is no mention of whether that user waits or just leaves without waiting. What to assume?
[SG]the customer will not wait and will leave immediately if the shop is at capacity (25 customers).

13: In Part A, can the script "usertests" be used for testing our xv6 Demand Paging logic, or does it work in a way that wont work for the changed logic?
[VG] - `usertests` should work after correctly implementing Demand Paging but it doesn't check whether demand paging is implemented correctly or not :)

14: In Part B, For Inspect last session do we only have to store the last session packets or like we also have to print them or can some other operations be also asked?
[DM] - You need to store only _the last_ captured session packets, that exactly is [Phase 4](https://karthikv1392.github.io/cs3301_osn/mini-projects/mini-project2#phase-4-the-packet-aquarium---saving-your-catch-2) and [5 in Part B](https://karthikv1392.github.io/cs3301_osn/mini-projects/mini-project2#phase-5-the-digital-forensics-lab---in-depth-inspection-6). That is to save them, to print them, and to be able to select any one of them and show an in depth analysis.

15: C-Shark, Phase 4
1. Suppose I `sudo ./cshark`, capture some packets, then ctrl-D it(exit).
2. Now I `sudo ./cshark` again, and `3. Inspect Last Session`.
    What should happen?
    
    a. I should display an error message
        b. I should display the packets captured in 1.
[DM] - If you have implemented persistent packet storing (not compulsory, no extra marks) then display packets from the last session else an error message is fine too.
16: In Part C, could you confirm if a sofa seat remains reserved for a customer until they finish payment or whether it is freed when that customer is taken for baking.
[SM] - sofa remains reserved until they finish payment. Once the last operation customer leaves is performed, then sofa seat becomes empty. In next second another customer can occupy.
17: should we continue to take input from terminal after eof and the tasks are completed (only exit on ctrl c), or it should be terminated immediately after eof and output for it is given?
[SM] - the input should be taken till <eof>. After that the simulation of the input should be started.
18: should there be any time between the customer taking a seat and requesting for cake(consider a chef is free)
[SM] - yes. Each action of the customer should take 1 second. Please check example.
19: In part B, if I press ctrl + c after choosing the interface (not during packet capture but while choosing from the main menu), should it again show the main menu or should it terminate the program?
[DM] - Main menu.

20: For Ctrl+C implementation in Part B, do we have to stop immediately or can we stop after the timeout of pcap_dispatch function?
[DM] - It must stop immediately (slight delay is fine due to too many packets being stored/proccessed, but for for lesser number of packets, it must immediate, not waiting for the timeout/keeping the timeout too small if in a loop).
21: when the customer pays, does he take 1second, and then the chef takes 2sec to accept the payment or overall payment is 2sec only?
[SM] - check the given example.
22: Are we expected to explain our approach in the ```README.md``` files for Part B and Part C?
[DM] - Not needed, just general assumptions (if valid) and instructions to run are fine.

23: In part-B (C-Shark) what should be the maximum size of the character array/buffer to store the name of the interface chosen by the user?
[DM] - 256 per device name should be enough.

24: Are we supposed to hande ctrl-D even while the packets are being recieved ? Are we supposed to exit the program completely on ctrl-D when packets are being recieved or we can ignore that ?
[DM] - Ctrl+D at any time (even when packet capturing) exits the program completely.

25: How do we handle the case where the memory is full and a new process creates a page fault? We can't replace any page in the memory as none of them belongs to that process.
[VG] - Yes you can't replace any other Page meaning there is no valid victim. In this case you need to terminate the process, make sure to follow log event ordering as mentioned in spec.

26: In part B, should the user be able to enter commands while sniffing?
[DM] - No
27: Part C,
Does a chef start baking a cake only after a customer does getcake()?
If chef_j started baking a cake after customer_i did getcake(), but some other chef had finished a cake before that, then does the customer wait for chef_j or does the customer take the first cake available to him anf leave? That is, is a particular customer associated with a particular chef?
[SM] - yes. yes. check example
28: Part B, can we safely assume that the macro __FAVOR_BSD is defined, because the struct definition of tcp and udp headers depend on it
[DM] - Yes

29: Suppose I run an HTTP sniffing session , then I run an ARP sniffing session and suppose ARP doesn't capture any packets , then when I run inspect last sniffing session , should it give me error or it should consider HTTP sniffing session inspection?
[DM] - Error as ARP was the last sniffing session, so display no packets captured or any apt messages.

30: For Part1, there is no mkfs, but its mentioned in the submission format, are we supposed to create it?
[VG] - Sync the repo.

31: As far as I understand the demand paging, ELF pages are loaded only when first used, so a few extra pages are allocated during execution. As a result, the free memory count at the end can differ slightly from the start, causing usertests to report lost pages. Upon checking free memory explicitly after usertests had terminated I found that all pages were available. So is this expected?
[VG] - Yes thats expected as in demand paging no of allocated pages changes dynamically. Make sure after usertest memory is reclaimed properly so there should not be any memory leak.

32: The xv6 file limit is only 274kb, the assignment specs expects max swap capacity of 4MB, is this a flaw, or are we expected to modify xv6's file system to support larger files or use multiple swap files or smtg?
[VG] - No, the 1024 capacity is a logical upper limit that means your data structure should handle till that. In testing xv6 size will full before that code should terminate gracefully with proper log.

33: In Part-A the assignment specifies that clean pages are to be discarded on eviction and swap slots must be freed on reloading. So, in case of a stack or heap page that has not been modified since last reloading from memory (i.e a clean page), if we are to evict it and so discard it are we not losing pages then. Should we handle these cases differently and write back to the swap space even though it is a clean page ?
[VG] - Thats correct you need to handle them. It would be updated in spec doc. So you would discard clean page only if a valid backing store still exist.

34: In part C , if a customer invokes bakecake , should the chef start baking it at the same time instant or 1 second later ? also same for invoking payment after recieving the cake ?
[SM] - 1 second later. PLease check example.

35: In part A, can we assume all pages are mapped read only at the start and every time there is a write, page fault is triggered, and permission is changed? Without that there is no inbuilt mechanism to detect dirty bits, so fault is not triggered and dirty bit would not be set.
[VG] - works, write your assumptions clearly in README.

36: If chef 1 baked the cake for customer 1, then can any other chef, eg chef 2 accept payment for customer 1
Below is mentioned on the website
When a customer’s cake is finished, any chef can accept payment, but because there is only one cash register, payment is accepted for one customer at a time.
[SM] - yes.

37: This seems to imply that only a customer that is sitting on the sofa is served, while the standing customers are served only after taking a seat. The example 2 is contradictory.Here, Customer 5123 requests for cake before sitting on the sofa, illegal.
[SM]- yes. Thankyou for pinting out. it's corrected and updated. he can order only once he takes seat.
    
38: When a customer’s cake is finished, any chef can accept payment, but because there is only one cash register, payment is accepted for one customer at a time. So how can customer 3157 pay before chef 3 has accepted payment for customer 2356, shouldn't register be locked until the chef accepts the payment
[SM] - No. at 28 Customer 3157 pays. but we can see the payment register is busy. SO, his oayment is not initiated. it is initiated at 31st second after completion of chef 2 completes.

39: In Part-A, Part-1: Demand Paging,
At process startup (exec), do not pre-allocate or load all program pages. [10 Marks]
This means I can allocate SOME (not all) pages right? So can I pre-allocate some stack frames that are used during process startup?
[VG] - Yes
    
    
40: In Part-C example 2:
23 Customer 1245 requests cake
24 Chef 1 bakes for Customer 1245
Here, Chef 1 bakes after 1 second
30 Customer 5123 requests cake
30 Chef 1 bakes for Customer 5123
here, chef 1 starts baking at the same timestamp. How?
[SM] - First one is correct. Sorry for the mistake. it is corrected.

41: For Part-C, can we write assumptions in README? Can we assume that customers always arrive one by one as shown in the examples?
[SM] - Sure you can write down. No, customers can come at same time.that's not a valid assumption.

42: For Part-C, can a customer request a cake before sitting on sofa? Or do they have to sit on sofa to request for cake?
[SM] - second one.

43: For Part-C, is it necessary that the flow be sorted by timestamp? Also, is it necessary to implement threading explicitly, or can we use our own logic so long as the output is correct?
[SM] - ues, it is timestamp, so you can't go back. So you need to keep it. sorted. Understand it's a simulation of the given input scenario. No, it is explicitly written in the doc you should use threads.
    
44: in phase3 should sniffing packet means should have to do all things which are done upto phase 2
[DM] - Yes, the only difference being rather than showing all packets on that interface, you show packets with that filter on that interface, while all layers are being displayed as in Phase 2.
    
45: In phase -3 filtering , does the numbering of the filtered packets matter? Can we number the packets 1,2,3,… or do they have to correspond to the index of the sniffed packet (say for http , cshark snifs packets 3 and 8 … can it number them as 1,2 or 3,8 like wireshark does)
[DM] - Either is fine.
    
    
46: In Part-A, the specs document does not specify what has to be done on forking a child process ? Are we supposed to decide that by ourselves ?
[VG] - You can assume normal xv6 semantics extended with demand paging, that means when a process forks, the child should inherit the same virtual mappings as the parent, but pages should only be loaded on demand when first accessed. (no need to implement Copy-On-Write)
    
    
47: In Part-A, we are specified to create swapfile during exec. So, assuming this, what do we do for a process that is forked from a parent process and not passed into exec? 
[VG] - When a process forks, the child inherits the parent’s address space but doesn’t get a new swapfile yet.
The child will create its own swapfile later when it calls exec().
    
48: In part-A page replacement Replacement is triggered only when kalloc() fails (system out of frames)., So to keep track of currently allocated pages in RAM, do we need to have maximum of 128MB / 4KB entries or we can just define some arbitary number as MAX_RESIDENT_PAGES.
[VG] - You don’t need to maintain one entry per physical frame just keep a per-process resident set table with a reasonable maximum. (state that clearly in readme)
    
49: In usertests, is it necessary for it to pass lazyalloc test as well, as ig that function tries to allocate beyond the max disk space. I am getting failed message like swap full due to disk limitations, and it shows failed test? is this acceptable?
[VG] - Yes(make sure it terminate cleanly with req logs)

50: in Part B, is it necessary to write cross-platform compatible code? Can I assume I'll run the code on Ubuntu/Linux?
[DM] - You shall be running the code on your own laptop on your preferred network.
    
51: struct proc_mem_stat { int pid; int num_pages_total; int num_resident_pages; int num_swapped_pages; int next_fifo_seq; struct page_stat pages[MAX_PAGES_INFO]; }; In this num_pages_total should include trampoline or not as it is shared between all processes.
[VG] - dont include trampoline pages.
    
52: If I choose the interface as bluetooth-monitor (Bluetooth Linux Monitor), and filter dns or http packets, I am not able to get any packets, ig cause interfaces like bluetooth0, bluetooth-monitor don't use standard Ethernet framing.for such cases, I am printing, Couldn't parse filter udp port 53: Bluetooth Linux Monitor link-layer type filtering not implemented. Is this fine, or is my understanding incorrect?
[DM] - It is fine, we won't be checking packets in it, though you should be able to open it.
    
53: For part C, does it take 1 sec for the customer to enter and stand as well, thats not mentioned in the examples.
[SM] Yes. Please follow as example.