Coding: Preliminary Patch
Once you have completed the design document, you can start coding. Your goal is to support the following system calls:
open,read,write,lseek,close,dup2,chdir,__getcwdfork,_exit(preliminary implementation without PID support)
Testing
You can run /testbin/hw4test to test your system calls. Example output (where most of the system calls except _exit are implemented) is shown below:
OS/161 kernel [? for menu]: p /testbin/hw4test
**********
* File Tester
**********
* write() works for stdout
**********
* write() works for stderr
**********
* opening new file "test.file"
* open() got fd 3
* writing test string
* wrote 45 bytes
* writing test string again
* wrote 45 bytes
* closing file
**********
* opening old file "test.file"
* open() got fd 3
* reading entire file into buffer
* attemping read of 500 bytes
* read 90 bytes
* attemping read of 410 bytes
* read 0 bytes
* reading complete
* file content okay
**********
* testing lseek
* reading 10 bytes of file into buffer
* attemping read of 10 bytes
* read 10 bytes
* reading complete
* file lseek okay
* closing file
**********
* testing getpid
* getpid() returned -1
**********
* testing fork (parent waits)
* Forked, in parent
* Forked, in child
* Child (pid 1) exited with status 11 (claimed as pid=-1)
**********
* testing fork (child finishes first)
* Forked, in child
* Forked, in parent
* Child (pid 1) exited with status 11 (claimed as pid=-1)
Operation took 2.527498413 seconds
OS/161 kernel [? for menu]:
Some notes on the test program:
- The program uses standard output and standard error. If you haven't implemented opening them for when the kernel's
pcommand starts a program, there won't be much output. - Although
getpidandwaitpidaren't implemented at this stake, in the kernel tested here, there are system call stubs that returnENOSYS(not implemented) without printing any messaage. (If you print a message, it will be interleaved with the test output, which is confusing.) - Likewise, because
waitpidisn't implemented yet,clocksleep(3)was added tocommon_proginmenu.cto pause before returning. This delays printing the kernel console prompt until after the test program has finished, so that the test output doesn't overlap with the kernel prompt.
Other Test Programs
The program /testbin/hash tests the open, read, and close system calls by reading a file and computing its hash. If run without a filename argument (which isn't supported at this stage), it will compute the hash of sys161.conf, and should produce the output Hash : 2559.
The program /testbin/conman confirms that standard input can be read by echoing it back to standard output. However, at this stage, since you haven't implemented waitpid, you can't make the kernel console wait for the child process to finish, so it will also try to read from standard input. Adding a long enough delay with clocksleep() in common_prog will allow you to type something before the kernel prompt appears.
Here's an example of running /testbin/conman, with a clocksleep delay of 30 seconds:
OS/161 kernel [? for menu]: p /testbin/conman
Wow, this is fun.
Everything I type gets printed. Can't make any mistakes though. No delete!
To exit, I need to press --> q
Operation took 29.639815059 seconds
OS/161 kernel [? for menu]: uthjj
If I'd taken longer than 30 seconds to type, the kernel prompt would have appeared before I finished typing. Then the kernel and the user process would have competed for input, whith each character I typed either being seen and echoed by the user process or being the kernel, so it'd look normal, but the kernel would have seen only a partial command until I finally pressed a q that was read by the user process.
Submission
Use the submit-this program as usual to submit your preliminary patch.
(When logged in, completion status appears here.)