Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Some demo programs related to the operating systems class

License

NotificationsYou must be signed in to change notification settings

lxylxy123456/ECS150Demo

Repository files navigation

  • Some demo programs related to the operating systems class(ECS 150).

Demos about synchronization

sync_barrier

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

Demos about page tables

Disclaimer

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.

page2frame

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:

  1. Compile the programpage2frame.c, run it, and record its pid.
  2. Read/proc/[pid]/maps and find index of the page with permission column-w-p (only writing permission).
  3. Check and print corresponding data in/proc/kpagecount and/proc/kpageflags.
  4. Read the page in/dev/mem, and print it in binary form (can be readusinghexdump orxxd).

The C program,page2frame.c, will:

  1. mmap a memory page with only writing permission.
  2. Fill the page with some specific pattern. Namely, some integers at thebeginning and "EOF" at the end.
  3. Print something (so that the Python program knows it has done with step1 and 2, and then go to sleep.

page_table

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 thedotcommand 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 tables

Sample page table ofpage2frame:Page table sample

page2frame in another system:pdf

Page table offind:pdf

About

Some demo programs related to the operating systems class

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp