Operating Systems 2017F Lecture 17: Difference between revisions
Line 47: | Line 47: | ||
*Purpose of data structures/objects<br> | *Purpose of data structures/objects<br> | ||
For the tutorial 6 he gave us a link for a reason. If you click on it you can search getpid and then dig deeper! For example cut and paste the line inside getuid function. | For the tutorial 6 he gave us a link for a reason. If you click on it you can search getpid and then dig deeper! For example cut and paste the line inside getuid function. <br> | ||
<br> | |||
Scheduling<br> | |||
Scheduler decides when what process should run at a high level<br> | |||
Questions: How does the scheduler work/kernel control when a program runs/how can you make sure one program does not take over CPU from anyone else?<br> | |||
CPU is given entirely to userspace processes to run most of the time |
Revision as of 18:53, 14 November 2017
Midterm Review
1. Execve and no it does not create a new process
6. uses of signals:
- kill process
- find out when child process is terminated
- start/stop a process
- detect when a program has made a ptr error
7. Pointers in C contain virtual memory addresses because the memory of a process is a virtual address space. Each process thinks it has its own stretch of memory.
8. processes make a sys call to allocate memory. execve -> then mmap and/or sbreak to allocate memory
9. shell opens the file output.txt.
10. mmap contents of file can allocate the contents of it into ram.
- comparing 1 mb of both files at a time will be less expensive
- only makes sense to mmap if you will access files multiple times
11. producer and consumer now have no way of talking to each other because they do not share the same memory.
12. no. there is a race condition. while loop loops while sem < 0. someone else could access and modify the variable between the while and the sem--;.
- you need special instructions to test and set the variable at the same time.
- also, sem isn't a ptr so it's a local variable.
Additional Notes
How do you do kernel hacking? Some tips for low level kernel code:
Be humble; You cannot know how everything works
Verify your assumptions as you go
Perform lots of experiments
Incremental Development, compile and run often
Check for errors ALWAYS or they will cascade and hurt you later
This will save you from later errors
Kernel has to live cleanly
Find another part of the kernel that is close to what you want to do (Search online! This is a good link: http://elixir.free-electrons.com/linux/v4.4.83/source)http://elixir.free-electrons.com/linux/v4.4.83/source)
You do not understand all abstractions and assumptions, so "pattern match" to minimize trouble
Realize that the assumptions behind code you don't necessarily match to your own. Spend the time reading other people's code.
Understand the "flow of control" inside the program
- Architecture
- Division of responsibilities
- Purpose of data structures/objects
For the tutorial 6 he gave us a link for a reason. If you click on it you can search getpid and then dig deeper! For example cut and paste the line inside getuid function.
Scheduling
Scheduler decides when what process should run at a high level
Questions: How does the scheduler work/kernel control when a program runs/how can you make sure one program does not take over CPU from anyone else?
CPU is given entirely to userspace processes to run most of the time