Presentation is loading. Please wait.

Presentation is loading. Please wait.

OS – Ex 1 Nezer J. Zaidenberg.

Similar presentations


Presentation on theme: "OS – Ex 1 Nezer J. Zaidenberg."— Presentation transcript:

1 OS – Ex 1 Nezer J. Zaidenberg

2 Administration Nezer J. Zaidenberg nzaidenberg@mac.com
I sit in Schreiber 9 Ex. Grader TBD THE COURSE HAS BEEN MODIFIED PLEASE ATTEND LECTURES EVEN IF YOU DO THIS COURSE 2ND TIME

3 Homework There will be 4 homework assignments
They will each be graded (bonus may apply) Total weight = 40% (total weight of test = 70%) Homework can be done in groups Each group must meet the ex. Checker and explain their work. a group were a single member will fail to explain his work will fail The homework will be checked on a computer with VMWare that you should download and verify 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 dedicted if the ex doesn’t work as supposed to or use the OS incorrectly

4 Using Linux The good but hard way – install Fedora core 9 on your computer. (Do this if you know what you are doing and at your own risk) The also possible way – download VM Player from VMWare.com (free) and use it with our vmware. Download Linux vmware We will distribute Vmware machine you can work on. There will also be method to invoke from university servers. The not recommended ways Using only user mode linux 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.

5 Using Linux under VMPlayer
Simulates mini computer inside your computer. Maybe slow 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 : qwerty User password : user Download from

6 User vs Root User – can run programs
Root – can run system programs. Administrator of system (usually owner or owner’s employee) User – can hardly cause damages. Root – prune to damages. Root – can use low-level system resources (such as row sockets) and setup kernel modules Most of the time we work as user; Sometimes(rarely) we work as root. When coding stuff on the kernel or running administration commands

7 What is kernel module Kernel module, (in simplest terms) is part of the OS, that can be insert into the OS and removed at run time. We can modify the OS by attaching kernel modules to the kernel Anybody can compile kernel modules but only root can insert them to a running system

8 Commands that deal with kernel modules
What modules are running? = lsmod Insert a module – insmod or modprobe (modprobe also support parameters) Remove a module – rmmod or modprobe –r

9 Coding in kernel space In kernel space the standard library (functions such as printf() etc.) doesn’t exist. Kernel developers have implemented kernel replications of most standard library functions. References Chapter 21 of beginning linux programming by Stones & Matthew Understanding the Linux kernel

10 Compiling “hello world” kernel module
This exercise will teach you how to write kernel module that prints “hello world” Compiling gcc –D__KERNEL__ -D__SMP__ -DMODULE –DMODVERSIONS –I/usr/src/linux/include –Wall –O2 –o module.o –c module.c Meanings __KERNEL__ = some kernel headers are also used in user process. This makes all #ifndef __KERNEL__ pick the correct code. __SMP__ = this module will be used in SMP system (practically all desktop computers when you will graduate will be SMP) MODULE = must be defined for the code to be compiled as kernel module MODVERSIONS = include module and kernel version (so that we will not load incorrect module into the kernel) -I/usr/src/linux/include = linux include source. (such as what replaces std lib and the OS headers itself)

11 Kernel module functions and source
Every kernel module must include <linux/module.h> and every kernel module with modversions must include <linux/modversions.h> Also each kernel module must implement init_module() and cleanup_module() function. (In OOD that would be called an “Interface”

12 Code #include <linux/module.h> #ifdef CONFIG_SMP #define __SMP__ #endif #ifdef CONFIG_MODVERSIONS #define MODVERSIONS #include <linux/kernel.h>

13 Code continue Int init_module(void) {
printk(KERN_ALERT, “hello, world\n”); } Void cleanup_module(void) printk(KERN_DEBUG, “bye bye cruel world\n”)

14 Explaining #macros -> will be explained later. So far treat them as a must Init, cleanup function = the interface Printk = a printf (or maybe syslog(2) type function that will send info to a file there is no libc in the kernel KERN_DEBUG = one of several levels of debug messages Other levels KERN_EMERG, KERN_ALERT, KERN_CRIT, KERN_ERR, KERN_WARN, KERN_NOTICE)

15 Homework – not for submission
Run the above code Check for kernel messages in /var/log Try to find out what kernel message level is the threshold in your machine


Download ppt "OS – Ex 1 Nezer J. Zaidenberg."

Similar presentations


Ads by Google