CSE 4105 System Programming · Lab 8

Processes · execve and Scheduling

mysh, a small shell; stack and scheduling experiments.

Tasks

The same steps as the lab slide. Do them on a Linux PC with the files from the zip; the tools below help you check your thinking first.

Lab 8.1 · Processes

  1. TODO 1 split the line into argv with strtok; end it with NULL
  2. TODO 2 fork; in the child execvp, or print the error and _exit(127)
  3. TODO 3 waitpid in the parent and report how the child ended
  4. TODO 4 cd as a built-in with chdir
  5. TODO 5 a trailing &: do not wait; collect later with WNOHANG

the finished shell (real session)

mysh> echo hello from a child
hello from a child
mysh> cd /tmp
mysh> pwd
/tmp
mysh> nosuchprog
mysh: nosuchprog: No such file or directory
[369 exited with status 127]
mysh> ./segv
[370 killed by signal 11]
mysh> sleep 1 &
[371 running in the background]
mysh> echo waiting
waiting
[371 done]

Think: why can cd not be a program like ls? (Hint: whose current folder would change?) Answer in your report.

Lab 8.2 · execve and Scheduling

  1. TODO 1 in stack_starter.c: count the envp strings (a NULL-ended array, like argv)
  2. TODO 2: point an Elf64_auxv_t * just past envp's NULL; print until AT_NULL
  3. Compare with LD_SHOW_AUXV=1 ./stack; build with -static and compare AT_BASE
  4. Predict the shares for nice 1, 5, 10, 19 from the weight table, then run ./shares N 5
  5. Run ./ctxsw; find CONFIG_HZ of your kernel and explain the hog's number

expected output (our machine, real)

$ ./stack hello world
argc = 3
argv[0] at 0x7ffe5cfa2366 -> "./stack"
argv[1] at 0x7ffe5cfa236e -> "hello"
argv[2] at 0x7ffe5cfa2374 -> "world"
envp: 203 strings, …
auxv AT_PAGESZ          0x1000
auxv AT_PHDR  …         0x55f059196040
…
$ ./shares 5 5
nice 0 : 2.99 s CPU (75.4%)
nice 5 : 0.98 s CPU (24.6%)
$ ./ctxsw
sleeper  voluntary_ctxt_switches:  100
hog      nonvoluntary_ctxt_switches: 276

Report: a table predicted vs measured for task 4, and one sentence per difference larger than 1 %.

Try it here

These run in your browser, with no server and no internet. They are built from the same reference programs as the lab, so their output matches what your finished C program should print. They do not replace the real lab: the kernel, gcc and your own code are the point.

Read the files

Every text file from lab08_files.zip. Read here, then download the zip to work on them.

    ← Lab 7All lecturesLab 9 →