OS – Ex 1

farrightSoftware and s/w Development

Aug 15, 2012 (4 years and 2 months ago)



There will be
homework assignments

They will each be graded
+ (There will be bonus)

Total weight =
% (total weight of test =

Homework can be done in groups

Each group must meet the ex. Checker and defend their work. the grade of the group will be
the grade of it’s worst member!

The kernel homework will be checked on a computer with VMWare that you should download
and verify. The User space code will be checked on VMWare

No rechecks for code that doesn’t run

No points will be deducted on code quality (unless we see real atrocities) but points will be
deducted if the ex doesn’t work as supposed to or use the OS incorrectly.

Defending homework

The main reason is policy

since the homework affect
grade to such extent it cannot be allowed without oral

This method have proven to be very effective in ensuring
students success on the final test.

It cannot be changed not even if you work alone.

What questions do we ask when you
defend your code?

50 questions are prepared for each ex. 3 random questions
per student.

Questions type : show me where you <do something>,
what does <this> line do? Why did you add this check etc.

No student that worked on the ex. Should fail. But it is
almost impossible to “fake”. (so please DO your

Strict timetable policy

In order to minimize hassle for you, we will give oral exam
on the homework within 1 week of dead line.

That means we need to schedule a room, invite checker
and grade everything within very short time!

Since we do all that

we believe students should be ready.
By not submitting homework in time you delay our
checking and ruin our system.

We are also firm believers on strict timelines.

Using Linux

The good but hard way

install on your computer. (Do this if you know what you
are doing and at your own risk we cannot and will not provide support if your
computer fail)

The also possible way

Download VM Player from VMWare.com (free) and use it
with our vmware.

We will distribute VMWare machine you can work on. (MTA

via library, TAU

Amir’s door) It will also be available on class on MTA.

The not recommended ways

Using only user mode linux on TAU.

Using your own different linux distribution

Using another UNIX

ETC… all those methods are at your own risks. Should anything fail, you will be sole
responsible due to all incompatibilities.

Using Linux under VMPlayer

Simulates computer inside your computer.

Slower then real PC but good enough for us.

For most practical purposes can be treated as a real
computer with real OS. (certainly for this course)

Root password : password

User password : user

Download from www.scipio.org/Courses/OS_Course

User vs Root


can run programs


can run system programs. Administrator of system (usually owner or
owner’s employee)


can hardly cause damages.


prune to damages.


can use low
level system resources (such as row sockets) and setup kernel

Most of the time we work as user

Sometimes (rarely) we work as root. When coding stuff on the kernel or running
administration commands. In Ubunto we login as user and sudo(1) when we need
root access

Assumed knowledge

We assume you know how to code in C in KR Level.

We assume you know how to handle strings

We assume you know how to do basic math

We assume you know how to allocate and free memory

We assume you know how to create functions and use
recursion, library functions and function pointers

We assume you know how to open files and folders

We assume you know what editor, compiler, debugger and
Make (build) is.

Using Linux

There are many manuals on the net. (Try

UNIX is a
word and vi is
letter abbreviation)

There is also a readme that comes with your VM

Some basic commands

mkdir, rmdir, cd

just like MS


list files (dir)


Text editor




remove (delete)

Coding and programming in Linux

First thing we need to do is edit a source file. (which is basically
a text file)

Create a source file in your favorite editor (I use vi.)

Compile using gcc

c “source file”

o “object file”

Link using gcc <objects>
o <binary>

This process can be automated by using Makefile

Run using ./<binary> (we don’t have . In the default search path)

Sample program

compile and run

Macintosh:~ scipio$ vi hello.c

Macintosh:~ scipio$ gcc
c hello.c
o hello.o

Macintosh:~ scipio$ gcc hello.o
o hello

Macintosh:~ scipio$ ./hello

hello world

Source of hello.c

#include <stdio.h>

int main(int argc, char * argv[])


printf("hello world

return 0;



Makefile (same as project file in other environments) is a
simple way to automate build process

Makefile works like that…

<Target> : <requirement>

<tab> <how to produce>

<next target>

For example for hello world the make can look like


all : hello

hello : hello.o

gcc hello.o
o hello

hello.o : hello.c

c hello.c
o hello.o

Using make

Macintosh:~ scipio$ make

c hello.c
o hello.o

gcc hello.o
o hello


The Linux debugger is gdb

You must compile with

g switch to include debug info
(same as debug/release build in other environments)

You can use gdb to trace (step, step into, next) your
programs. Gdb has a graphical front end


Usually though you will just examine core dump. (core is
what your program leaves when it crashes)


int main()


int i=

int j=

int k=i/j;


Using UNIX to debug…


c 999999


g crash.c

o crash



c core ./crash

Program received signal EXC_ARITHMETIC, Arithmetic exception.

0x00001ff3 in main () at crash.c:5


int k=i/j;

More options

Gcc and gdb has lots more options, while Make is fully
programmable environment.

We don’t teach any of these due to time constraints (and
because it’s off topic) but new options may be introduced
as we go along. You are welcome to use any option you
want and do your own web research.

You may also use anything you find in your homework.

Using IDE under Linux

There are plenty of IDE that act as a wrapper to the above
such as (partial list)






We don’t teach or support them, but you may use them for
your homework.

Ex. 0

We give you ex.
as an optional ex. To iron out your C
skills and code under Linux. Should you submit it, it will be
checked. But it is not obligatory and will not effect your
grade. (there is also no defense on that one)

You should probably google most of your problems (there
are plenty of good guides) you can also Email Nezer and
Tomer if you cannot find the answer in google.

Ex. 0

Create a user shell supporting the following commands:

DIR = list files

CD = change directory (CD .. = usual meaning)

Everything else = try to execute something with the same
file name in the current directory using system(3)

Submit source and makfile.