Last time: UNIX/Linux, Windows, and XINU
√ - provide system service to processes
√ - are implemented by a special instruction(“ta” for Sparc) itself in user code, but causes execution to transfer into kernel to run, and when done, return to next user instruction
√ - can be called from a C program via an “envelope function” in C library
o Sec 2: syscalls (open, close, …)
o Sec 3: portable standard C library (fopen, fclose, …)
√ - are not portable: fork + exec in UNIX <----> CreateProcess(…) in Windows
XINU: everything is in one address space
- multiple user processes: can just call the kernel syscall for
- kernel code
Xinu processes are like UNIX threads
- share data vars (external C vars)
![]() |
Comer P5: ex1.c
putc(CONSOLE, ‘h’);
- CONSOLE: dev, standard output for whole system(single user)
- need: #include <stdio.h>
o #define CONSOLE 100
- Note: replace “conf.h” with “stdio.h” in Chapter1 programs (user-level program)
To run ex1.c:
1. build it into Xinu using cross-compiler/loader
- ex1.lnx <-- file on UNIX system
o compilation of ex1.c to ex1.opc(object file) which has undefined symbol “putc”
o cross-loader: combines ex1.opc with Xinu library(*.opc, putc implementation code) & a small C library(*.opc, printf in here, calls putc)
§ static load: no DLLs, all codes needed is in executable
o output ex1.lnx: contains main, putc code, Xinu core system
2. Download ex1.lnx into online SAPC, and run it.
create(prA, 2000, 20, “proc 1”, 0)
- create a process in suspended state
- return pid
o 2000: stack size (NOTE: never use 200 here, it’s too small: change the book examples)
o 20: priority
o 0: no args
- resume(pid)
o put suspended pid into runnable state
Semaphores: exist to coordinate concurrent threads/processes
- can be used for mutex (mutual exclusion)
o if a resource can be used by only one thread at a time(eg. data structure in memory)
§ we need mutex to guard the resource
· need API
·
if some other thread is using, then
wait
§ Ex.