- Notifications
You must be signed in to change notification settings - Fork0
Some demo programs related to the operating systems class
License
lxylxy123456/ECS150Demo
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Some demo programs related to the operating systems class(ECS 150).
This is a synchronization barrier implemented using semaphores. There is anargument that can turn this program into an incorrect implementation. Theprogramsync_barrier.py
also contains a demo that shows how thissynchronization barrier works.
The correct behavior of the program with n threads is to print "0" for n times,then print "1" for n times, and so on. Each thread prints one "0", then one "1",and so on.
To run the correct one, use
python3 sync_barrier.py# 10 threads by defaultpython3 sync_barrier.py 100# Specify number of threads
To run the incorrect one, use
python3 sync_barrier.py 100 1
These demos are very likely to be OS and machine dependent. For example,the memory page size of 4096 bytes is hard-coded. I only tested it on a Linux4.9.189 x86_64 machine. Using other operating systems and CPU architecturesmay result in error in the program.
This demo gets a memory page of a process in user space by directly readingmemory frame from the kernel space.
To run this demo,you need a Linux kernel which is compiled withCONFIG_STRICT_DEVMEM=n
. Or the last step of reading/dev/mem
will fail.For some hints on compiling, seehere.
To run the demo, use:
sudo python3 page2frame.py | hexdump -C
The Python program,page2frame.py
, will:
- Compile the program
page2frame.c
, run it, and record its pid. - Read
/proc/[pid]/maps
and find index of the page with permission column-w-p
(only writing permission). - Check and print corresponding data in
/proc/kpagecount
and/proc/kpageflags
. - Read the page in
/dev/mem
, and print it in binary form (can be readusinghexdump
orxxd
).
The C program,page2frame.c
, will:
mmap
a memory page with only writing permission.- Fill the page with some specific pattern. Namely, some integers at thebeginning and "EOF" at the end.
- Print something (so that the Python program knows it has done with step1 and 2, and then go to sleep.
This demo displays the virtual page table of a program. This program uses thegraphviz module in Python 3, which can beinstalled usingpip
. You also need to installgraphviz
so that thedot
command is available.
To run the demo, which shows the page table forpage2frame.c
, use:
python3 page_table.py /output/image.pdf
You can use any other formats that graphviz supports (e.g.png
,jpg
)
To view page table for some existing process with pid[pid]
, use:
python3 page_table.py /output/image.pdf [pid]
Note: this program is still evolving.
Sample page table ofpage2frame
:
page2frame
in another system:pdf
Page table offind
:pdf