42
OS course – OS course – lecture 1 lecture 1 Nezer J. Zaidenberg Nezer J. Zaidenberg

OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Embed Size (px)

Citation preview

Page 1: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

OS course – OS course – lecture 1lecture 1

Nezer J. ZaidenbergNezer J. Zaidenberg

Page 2: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

AnnouncementsAnnouncements

Lecturer : Prof. Amir AverbuchLecturer : Prof. Amir Averbuch

Tutoring assistant :Mr. Nezer ZaidenbergTutoring assistant :Mr. Nezer Zaidenberg

Ex. Grader : Mr. Tomer MargalitEx. Grader : Mr. Tomer Margalit

The course form has changed since previous The course form has changed since previous years. It is recommended that you will years. It is recommended that you will attend lectures even if you taken this attend lectures even if you taken this course previouslycourse previously

Page 3: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

ScribeScribe

Following success last term…Following success last term…

1-2 Volunteers are needed as scribe1-2 Volunteers are needed as scribe

Scribe should attend every lecture and take notes.Scribe should attend every lecture and take notes.

Once a month the scribe will meet me (Nezer) to check and review Once a month the scribe will meet me (Nezer) to check and review the class notes.the class notes.

Notes will be published to the class in order to prepare for the test Notes will be published to the class in order to prepare for the test and homeworkand homework

Scribe duty well done will be considered as one homework exercise Scribe duty well done will be considered as one homework exercise submitted at 100 grade. (so scribe do gets something for effort) submitted at 100 grade. (so scribe do gets something for effort)

A second benefit is off course reviewing the material!A second benefit is off course reviewing the material!

People volunteering for scribe duty should contact Nezer via email. People volunteering for scribe duty should contact Nezer via email.

Page 4: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

GradesGrades

55% exercises55% exercises

55% exam (3 best are 15% worst is 10%) 55% exam (3 best are 15% worst is 10%)

The exam will include multiple choice The exam will include multiple choice questions. Most of which will be based on questions. Most of which will be based on the homework!the homework!

You must pass both the exam and the You must pass both the exam and the homework to pass this course!homework to pass this course!

Page 5: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

ReferencesReferences

The main books for this course is The main books for this course is

Understand the Linux kernel 3Understand the Linux kernel 3rdrd edition (For kernel edition (For kernel space)space)

Advanced programming for the UNIX environment 3Advanced programming for the UNIX environment 3rdrd edition by Richard W. Stevens (For user space)edition by Richard W. Stevens (For user space)

Additional books (that will be noted on specific Additional books (that will be noted on specific lectures)lectures)

UNIX filesystems by S. PateUNIX filesystems by S. Pate

Beej Manual for network programming (web guide)Beej Manual for network programming (web guide)

Solaris internals by Jim MauroSolaris internals by Jim Mauro

Page 6: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Course outlineCourse outline

The goal of this course is to gain practical The goal of this course is to gain practical understanding of the OSunderstanding of the OS

The course is very practical with several The course is very practical with several homework assignments and exam based on the homework assignments and exam based on the homeworkhomework

You will have to defend your workYou will have to defend your work

The course will focus on UNIX OS and in The course will focus on UNIX OS and in particular Linuxparticular Linux

The exercises will be mainly coding work or The exercises will be mainly coding work or reviewing kernel and low-level user code.reviewing kernel and low-level user code.

Page 7: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What this course is not What this course is not aboutabout

Coding (to the extent of coding standards, Coding (to the extent of coding standards, best coding practices or efficiency)best coding practices or efficiency)

MPP (beyond simple sync algorithms)MPP (beyond simple sync algorithms)

Network algorithms Network algorithms

EncryptionEncryption

Etc. Etc.

This code is on OS and OS related This code is on OS and OS related programming only programming only

Page 8: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What is OSWhat is OS

Once upon a time there was no operating systemsOnce upon a time there was no operating systems

Developers used to develop hardware and software, Developers used to develop hardware and software, together with everything needed to make the application together with everything needed to make the application runrun

As computers become more standard and tasks become As computers become more standard and tasks become common several tasks stood out as needed by all (or common several tasks stood out as needed by all (or practically all) software.practically all) software.

Those common tasks became “OS” and were supplied by Those common tasks became “OS” and were supplied by 33rdrd party vendors party vendors

Commercial software used to require specific OS. This Commercial software used to require specific OS. This became one of the first practices of “code reusability”became one of the first practices of “code reusability”

Page 9: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Common OS tasksCommon OS tasks

Memory managementMemory management

Hardware (driver) supportHardware (driver) support

Task schedulingTask scheduling

File managementFile management

User management (on multi-user systems)User management (on multi-user systems)

Software providers developed a single software for all Software providers developed a single software for all those components (and more) – the OSthose components (and more) – the OS

This software became the base for all further software This software became the base for all further software developmentdevelopment

Page 10: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What the OS includesWhat the OS includes

Core OS functionCore OS function Process managementProcess management User managementUser management File managementFile management Memory managementMemory management Hardware managementHardware management Network managementNetwork management

Additional functions are added and removed according to political and Additional functions are added and removed according to political and marketing scenariosmarketing scenarios Initial UNIX implementation had built in C compiler (sold separately with Initial UNIX implementation had built in C compiler (sold separately with

almost all modern OS)almost all modern OS) Most UNIX OS comes with wide range of servers such as ftp server, telnet Most UNIX OS comes with wide range of servers such as ftp server, telnet

server, daytime server, printing server and even HTTP server, J2EE server, daytime server, printing server and even HTTP server, J2EE platform, etc.platform, etc.

Many OS also come with GUI (windows, OSX aqua, X Windows) and other Many OS also come with GUI (windows, OSX aqua, X Windows) and other user tools (calculator, Text processor etc.)user tools (calculator, Text processor etc.)

Microsoft wished to add Internet Explorer, Windows media player etc. as Microsoft wished to add Internet Explorer, Windows media player etc. as part of the OS. However, the European union prevented the inclusion of part of the OS. However, the European union prevented the inclusion of media player in all windows sold in Europe… (anti trust reasons)media player in all windows sold in Europe… (anti trust reasons)

The course will deal with “CORE OS” functions only. These services are The course will deal with “CORE OS” functions only. These services are usually managed by the OS “Kernel”usually managed by the OS “Kernel”

We will focus on UNIX environment, Linux, Xubunto distributionWe will focus on UNIX environment, Linux, Xubunto distribution

Page 11: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What we will coverWhat we will cover

UNIX software developmentUNIX software development

ProcessProcess What is a processWhat is a process Memory managementMemory management Opening filesOpening files

Multi taskingMulti tasking Multi processMulti process Multi threadingMulti threading SyncSync

Memory managementMemory management

NetworkNetwork

Kernel developmentKernel development IO devices ( char device and block device )IO devices ( char device and block device ) File systemsFile systems

Page 12: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What is UNIXWhat is UNIX

UNIX is a general term for lots of thingsUNIX is a general term for lots of things

UNIX is the name of historical OS developed in 1970’s in Bell labsUNIX is the name of historical OS developed in 1970’s in Bell labs

It’s also a trademarkIt’s also a trademark

UNIX may refer to set of standards (POSIX) that defines OS interface UNIX may refer to set of standards (POSIX) that defines OS interface that many OS followthat many OS follow

UNIX is also general name for a family of many proprietary OS that UNIX is also general name for a family of many proprietary OS that were tested for standard completion. None of these OS is called UNIX were tested for standard completion. None of these OS is called UNIX but usually their name has an X that gives them away (AIX, OSX, HP-but usually their name has an X that gives them away (AIX, OSX, HP-UX, IRIX) with Solaris as the exceptionUX, IRIX) with Solaris as the exception

Commercial UNIX OS pay royalties to use the UNIX trademarkCommercial UNIX OS pay royalties to use the UNIX trademark

Since UNICES (plural for UNIX) share the same API and design principle Since UNICES (plural for UNIX) share the same API and design principle it is relatively easy (but not effortless) to port software from one UNIX it is relatively easy (but not effortless) to port software from one UNIX to the other.to the other.

Page 13: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX-Like OS’sUNIX-Like OS’s

Open source OS (such as Linux, FreeBSD, OpenBSD) that Open source OS (such as Linux, FreeBSD, OpenBSD) that were not tested by standard committee (but tend to have were not tested by standard committee (but tend to have the same API) are often referred to as UNIX-like.the same API) are often referred to as UNIX-like.

Open Source OS’s also don’t pay royalties and cannot be Open Source OS’s also don’t pay royalties and cannot be officially named UNIX (due to trademark rules)officially named UNIX (due to trademark rules)

Open source UNIX-Like OS have become more and more Open source UNIX-Like OS have become more and more popular (especially Linux) in many fields more common then popular (especially Linux) in many fields more common then real “UNIX” boxes.real “UNIX” boxes.

Today, for most people, UNIX means an OS with specific set Today, for most people, UNIX means an OS with specific set of API and applications regardless of standards testing. (so of API and applications regardless of standards testing. (so many people will say Linux is as much of a UNIX as AIX, many people will say Linux is as much of a UNIX as AIX, Solaris and OSX are.) Solaris and OSX are.)

So it is common jargon for both UNIX and UNIX-like OS’s to So it is common jargon for both UNIX and UNIX-like OS’s to be considered UNIX. (at least for this course)be considered UNIX. (at least for this course)

Page 14: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX OS internalsUNIX OS internals (IMPORTANT) (IMPORTANT)

UNIX OS and the UNIX API is built on top of two UNIX OS and the UNIX API is built on top of two basic principalsbasic principals Process Process FileFile

Almost all OS services are implemented as either Almost all OS services are implemented as either process or file. (for example the system logger is process or file. (for example the system logger is a “process” while a socket is a file.)a “process” while a socket is a file.)

This is one of the first implementations of the This is one of the first implementations of the interface design patterninterface design pattern

Throughout the course we will see how complex Throughout the course we will see how complex services are handled using these two basic services are handled using these two basic concepts.concepts.

Page 15: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX history

UNIX (acr. for uniplexed information) was initially pun on multics (OS that is UNIX (acr. for uniplexed information) was initially pun on multics (OS that is virtually extinct that allowed for multi-user to run multiple tasks on multi virtually extinct that allowed for multi-user to run multiple tasks on multi process environment) and was the name of OS that was developed at bell process environment) and was the name of OS that was developed at bell labs for their PDP11 computers.labs for their PDP11 computers.

Original UNIX developers wanted to build a better multics.Original UNIX developers wanted to build a better multics.

The OS was initially distributed in source form so that anybody can modify The OS was initially distributed in source form so that anybody can modify and customize it.and customize it.

The source was later brunched into two main trunks SYSV and BSD code The source was later brunched into two main trunks SYSV and BSD code (with both brunches often borrowing code from each other)(with both brunches often borrowing code from each other)

Most modern Unices are usually based on either of those brunches.Most modern Unices are usually based on either of those brunches.

Commercial UNIX today mainly in high end server, workstation and desktop Commercial UNIX today mainly in high end server, workstation and desktop market. market.

Open source UNIX tends to rule several market segments (Linux and apache Open source UNIX tends to rule several market segments (Linux and apache rule the http serving and Linux practically runs on all Wireless routers.) and rule the http serving and Linux practically runs on all Wireless routers.) and is heavy favorite on several others (running database servers)is heavy favorite on several others (running database servers)

Page 16: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX OS in the wild UNIX OS in the wild (partial list)(partial list)

SVR4 UnicesSVR4 Unices

Solaris and Open Solaris – Unix by SUN MicrosystemsSolaris and Open Solaris – Unix by SUN Microsystems

HP-UX – Unix by HPHP-UX – Unix by HP

Linux – The most popular open source OS (sponsored by Google, RedHat, IBM, Silicon Linux – The most popular open source OS (sponsored by Google, RedHat, IBM, Silicon graphics, Novell and more)graphics, Novell and more)

AIX – Unix by IBMAIX – Unix by IBM

BSD UnicesBSD Unices

OS X and Darwin iPhoneOS – Apple OS (OS X is the proprietary version and darwin is the OS X and Darwin iPhoneOS – Apple OS (OS X is the proprietary version and darwin is the open source version)open source version)

FreeBSD, NetBSD, OpenBSD – Open source BSD distributionsFreeBSD, NetBSD, OpenBSD – Open source BSD distributions

NOT UNIX systems (and how much they support POSIX)NOT UNIX systems (and how much they support POSIX)

Windows – not UNIX. But cygwin (open source) and microsoft POSIX subsystems each Windows – not UNIX. But cygwin (open source) and microsoft POSIX subsystems each provide compatibility layerprovide compatibility layer

Z/OS or MVS – IBM OS for mainframe – doesn’t follow UNIX at all but have a compatibility Z/OS or MVS – IBM OS for mainframe – doesn’t follow UNIX at all but have a compatibility layerlayer

Page 17: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX API summaryUNIX API summary

All UNIX and UNIX like OS’s follow the same API All UNIX and UNIX like OS’s follow the same API

All OSs that follow the UNIX API share similar design All OSs that follow the UNIX API share similar design principles and conceptsprinciples and concepts

As long as we program using the UNIX API it is As long as we program using the UNIX API it is relatively easy to port from one OS to the other (and relatively easy to port from one OS to the other (and for a developer or administrator from one for a developer or administrator from one environment to move to another)environment to move to another)

Please note – some UNIX OS’s also have proprietary Please note – some UNIX OS’s also have proprietary “non POSIX” APIs to support more features (for “non POSIX” APIs to support more features (for example OSX COCOA) naturally such features cannot example OSX COCOA) naturally such features cannot be ported easily. be ported easily.

Page 18: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

UNIX acceptanceUNIX acceptance Super computers – 88.6% of top 500 world super computers run Linux. 99% run Super computers – 88.6% of top 500 world super computers run Linux. 99% run

UNIXUNIX

Midrange servers (UNIX traditional role) – AIX is the most popular midrange Midrange servers (UNIX traditional role) – AIX is the most popular midrange servers in the financial industry while Solaris and HP-UX contend for the crown in servers in the financial industry while Solaris and HP-UX contend for the crown in Telco enterprisesTelco enterprises

Low end servers - About 70-75% of web servers (and most J2EE platforms) run on Low end servers - About 70-75% of web servers (and most J2EE platforms) run on Linux. Many network products (firewalls, switches, routers) are based on LinuxLinux. Many network products (firewalls, switches, routers) are based on Linux

High end Desktops and workstations – Over 65% of workstations and desktops High end Desktops and workstations – Over 65% of workstations and desktops costing above 1000 USD run OSXcosting above 1000 USD run OSX

Smart phones – both iPhoneOS (OSX) and Google Android (Linux) are unices Smart phones – both iPhoneOS (OSX) and Google Android (Linux) are unices

Databases – Sun was recently acquired by Oracle and Solaris will be the OS used Databases – Sun was recently acquired by Oracle and Solaris will be the OS used by Oracle’s Exadata. UNIX is also Tier-1 for most database vendorsby Oracle’s Exadata. UNIX is also Tier-1 for most database vendors

Embedded systems – VxWorks (arguably the most popular embedded OS) is POSIX Embedded systems – VxWorks (arguably the most popular embedded OS) is POSIX complaint. Linux dominates STB and IGD marketscomplaint. Linux dominates STB and IGD markets

Storage – most storage products run on top of UNIX (such as Linux or AIX)Storage – most storage products run on top of UNIX (such as Linux or AIX)

SAP environments – are typically managed by UNIX hostsSAP environments – are typically managed by UNIX hosts

Page 19: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Almost regardless of the Almost regardless of the industry or company you industry or company you will end up working for… will end up working for…

UNIX skills thought in UNIX skills thought in this course will be a vital this course will be a vital

tool in your toolboxtool in your toolbox

Page 20: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

GNU source and the FSF

GNU – acr. For “GNU’s not UNIX” GNU – a public license granting permission to use,

modify and redistribute code provided it remains GNU

FSF – acr. For “free software foundation” FSF – distribute the source for most of the free UNIX

applications (The unix look and feel). Promote the GNU license

Linux kernel – the “main functionality” of the OS developed by volunteers (not the FSF, but the groups are connected) under the the GNU license

Page 21: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Free as in beer – free as in speech

Beer – when you get a free beer – you can drink it. But not order the entire bar for a round of free beer!

Speech – when you hear an idea you can repeat it and incorporate it in your own speeches.

Sometimes the OS is included for the price of the box (free as in beer) but you cannot modify it!

The open source community looks for “free as in speech” software. And only “free as in speech” is considered free. (GPL, LGPL, BSD, MIT are all “free” while commercial free licenses are not considered “free”.)

In neither case – free does not refer to distribution and support fees which may apply.

Page 22: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

The many types of free

MIT license – allow you to do what ever you want with the code

BSD license – allow modification and redistribution (modification may not be free). You must keep credits to original author

GNU GPL – modifications (derived work) must be free GNU LGPL – modification must be free, but linking with GNU

source is not a modification (license used by GNU libraries) Other free licenses - check on FSF website Commercial Open source – you may view the source but not

use it commercially or you may edit the source, but your modification belong to specific company or modifications may not be redistributed. Are not considered “free” (such as Apple public license, Sun Public license, Netscape public license, MySQL)

Dual license – software available as GPL (if you modify you must open the source of the modification) same software is also available with closed source (you can modify and not open the source) for paying customers. This is the business model of many open source companies

Page 23: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Introducing Linux….Introducing Linux….

Page 24: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

History of LinuxHistory of Linux

In the early 1990’s there were commercial UNIX (SYS V) and In the early 1990’s there were commercial UNIX (SYS V) and free UNIX (BSD)free UNIX (BSD)

A T&T (copyright holders of SYS V) sued BSDi (BSD) for A T&T (copyright holders of SYS V) sued BSDi (BSD) for copyright infringement. BSD was crippled and many copyright infringement. BSD was crippled and many stopped using itstopped using it

During the legal vaccum a young Finnish student – Linus During the legal vaccum a young Finnish student – Linus Turvalds started implementing UNIX for intel 80386 from Turvalds started implementing UNIX for intel 80386 from scratch. The OS he developed was called Linuxscratch. The OS he developed was called Linux

Linus developed Linux “Just for fun”Linus developed Linux “Just for fun”

With BSD in legal struggle and Linux proving itself as With BSD in legal struggle and Linux proving itself as efficient and scalable alternative Linux started growing in efficient and scalable alternative Linux started growing in popularitypopularity

Linux was adopted by FSF for it’s GNU/Linux platformLinux was adopted by FSF for it’s GNU/Linux platform

Page 25: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Linux todayLinux today

Linux today is the most widely used UNIX OS Linux today is the most widely used UNIX OS (arguably the most widely used OS) found in (arguably the most widely used OS) found in cell phones, netbooks, embedded systems, cell phones, netbooks, embedded systems, notebooks, desktops, workstations, servers notebooks, desktops, workstations, servers and supercomputersand supercomputers

Linux runs on most architectures today (x86, Linux runs on most architectures today (x86, Itanium, ARM, Power, MIPS, s390 and a lot Itanium, ARM, Power, MIPS, s390 and a lot more)more)

Is distributed by commercial companies in Is distributed by commercial companies in what is known as a Linux distribution.what is known as a Linux distribution.

Page 26: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

What is Linux What is Linux distributiondistribution

Linux distribution is a gathering of software Linux distribution is a gathering of software from several sources, compiling them and from several sources, compiling them and branding them by single companybranding them by single company

All Linux distribution include the Linux kernel All Linux distribution include the Linux kernel and most GNU sources (thereby Linux and most GNU sources (thereby Linux distribution….) distribution….)

Linux distributions by Red hat SuSe, debian, Linux distributions by Red hat SuSe, debian, Ubunto, slackware have been popularized.Ubunto, slackware have been popularized.

On this course we will focus on Xubunto 9.04 On this course we will focus on Xubunto 9.04

Page 27: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Differences between Differences between distributionsdistributions

Distributions differentiate themselvesDistributions differentiate themselves Look and feelLook and feel Ideology (only free stuff vs. free as in beer also Ideology (only free stuff vs. free as in beer also

allowed vs. trademark images disallowed (such as allowed vs. trademark images disallowed (such as firefox logo) vs. commercial stuff included)firefox logo) vs. commercial stuff included)

Commercial supportCommercial support Other factors (can be loaded from CD, default Other factors (can be loaded from CD, default

language and supported languages etc.)language and supported languages etc.)

Why and what is XubuntoWhy and what is Xubunto The popular Ubunto with X (i.e. not KDE or Gnome) The popular Ubunto with X (i.e. not KDE or Gnome)

desktopdesktop The lowest foot print and hardware requirements The lowest foot print and hardware requirements

of all modern Ubunto flavoursof all modern Ubunto flavours

Page 28: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

The “founding fathers” of The “founding fathers” of Linux (partial list)Linux (partial list)

Linus Torvalds – Finnish – creator and Linus Torvalds – Finnish – creator and maintainer. About 2% of the current Linux maintainer. About 2% of the current Linux code (which is A LOT) is Linus’s code (which is A LOT) is Linus’s

Alan Cox – WalshAlan Cox – Walsh

Greg Kroah-Hartman - AmericanGreg Kroah-Hartman - American

Ingo Molnar – HungarianIngo Molnar – Hungarian

Robert Love – AmericanRobert Love – American

Page 29: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Shaped UNIX (partial Shaped UNIX (partial list)list)

Bill JoyBill Joy

Eric S. RaymondEric S. Raymond

Richard M. StallmanRichard M. Stallman

Ken ThompsonKen Thompson

Dennis RitchieDennis Ritchie

Marshall Kirk McKusickMarshall Kirk McKusick

Page 30: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

But maybe we are moving But maybe we are moving too fast here…too fast here…

Page 31: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Why do we need OS in Why do we need OS in the first Placethe first Place

Well we don’t NEED OS. But we want to.Well we don’t NEED OS. But we want to.

Almost every piece of software require some set Almost every piece of software require some set of services such as managing files, allocating of services such as managing files, allocating memory and usually opening threads, syncing memory and usually opening threads, syncing etc.etc.

Initially people implemented it from scratch Initially people implemented it from scratch with any new software.with any new software.

OS is the basic set of services which allows us to OS is the basic set of services which allows us to write our software.write our software.

The strategy of rewriting the OS with a new The strategy of rewriting the OS with a new software is almost extinct since long ago.software is almost extinct since long ago.

Page 32: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

OS code and User codeOS code and User code

OS code – usually invoked in “the kernel” is OS code – usually invoked in “the kernel” is the code that “makes the computer work”. the code that “makes the computer work”. Including drivers, memory management etc. Including drivers, memory management etc.

User code – most code we writeUser code – most code we write

In this code we will use the terms Userland In this code we will use the terms Userland and kernelspace to distinguish between and kernelspace to distinguish between them.them.

We will write both kinds of code in the We will write both kinds of code in the exercisesexercises

Page 33: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Where does the OS Where does the OS “ends”“ends”

The OS API is often called “system calls”The OS API is often called “system calls”

Often when we write code in C we call library Often when we write code in C we call library functions (such as printf, fopen, malloc) that functions (such as printf, fopen, malloc) that provide us with “OS” services (such as provide us with “OS” services (such as producing output, opening a file, allocating producing output, opening a file, allocating memory)memory)

Those are not system calls but C wrappers to Those are not system calls but C wrappers to system calls. (the C wrappers remain the system calls. (the C wrappers remain the same even on non-POSIX systems such as same even on non-POSIX systems such as windows)windows)

Page 34: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

requesting helprequesting help

In UNIX when we want brief help on something we can In UNIX when we want brief help on something we can type man (something) and get the help page. (try it. For type man (something) and get the help page. (try it. For example man man)example man man)

When the man refers to command line executable we will When the man refers to command line executable we will find the manual in section 1 of the manfind the manual in section 1 of the man

When the man refers to a system call we will find the When the man refers to a system call we will find the manual in section 2 of the manmanual in section 2 of the man

When the man refers to a library function we will find the When the man refers to a library function we will find the manual in manual 3 of the manmanual in manual 3 of the man

When a concept is found in two or more sections we can When a concept is found in two or more sections we can request the right manual by typing “man 1 write” or request the right manual by typing “man 1 write” or “man 2 write” (try it!)“man 2 write” (try it!)

Page 35: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Common conventionCommon convention

When discussing executable (such as ls) we When discussing executable (such as ls) we will use (1) after the executable name (for will use (1) after the executable name (for example ls(1))example ls(1))

Similarly when discussing system calls and Similarly when discussing system calls and library functions we will use 2 and 3 library functions we will use 2 and 3 respectfully. (open(2), printf(3))respectfully. (open(2), printf(3))

There may be some inconsistencies on There may be some inconsistencies on sections between UNIX flavours (functions sections between UNIX flavours (functions moving between section 2 and 3) but it’s rare. moving between section 2 and 3) but it’s rare.

Page 36: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Library code relation with Library code relation with OS codeOS code

Library functions, are invoking OS code to Library functions, are invoking OS code to complete their workcomplete their work

For example printf(3) (short for print For example printf(3) (short for print formatted) parses the input and format the formatted) parses the input and format the text. Then it calls for write(2).text. Then it calls for write(2).

Printf(3) is library function (and not OS Printf(3) is library function (and not OS function) while write(2) is a system call.function) while write(2) is a system call.

Page 37: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Some unix file related Some unix file related system calls you should system calls you should

already knowalready know Open(2)Open(2)

Close(2)Close(2)

Read(2)Read(2)

Write(2)Write(2)

To refresh your memory about these functions To refresh your memory about these functions type “man 2 open” to get the function C type “man 2 open” to get the function C info.info.

Page 38: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Example – man openExample – man open

OPEN(2) BSD System Calls Manual OPEN(2) BSD System Calls Manual OPEN(2)OPEN(2)

NAMENAME

open -- open or create a file for reading or writingopen -- open or create a file for reading or writing

SYNOPSISSYNOPSIS

#include <fcntl.h>#include <fcntl.h>

int open(const char *path, int oflag, ...);int open(const char *path, int oflag, ...);

DESCRIPTIONDESCRIPTION

The file name specified by path is opened for reading The file name specified by path is opened for reading and/or writing …and/or writing …

Note section 2 for system call

This is a man page from OSX which is BSD system

Open is the system call name

What the system call

does

Required header to use this function

C style function declaration (prototype)

Brief description

Page 39: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

More from man More from man open(2)open(2)

… … (description snipped)…(description snipped)…

RETURN VALUESRETURN VALUES

If successful… (snipped)If successful… (snipped)

ERRORSERRORS

The named file is opened… (snipped)The named file is opened… (snipped)

SEE ALSOSEE ALSO

chmod(2), close(2), dup(2), getdtablesize(2), lseek(2), read(2), chmod(2), close(2), dup(2), getdtablesize(2), lseek(2), read(2), umask(2), write(2)umask(2), write(2)

HISTORYHISTORY

An open() function call appeared in Version 6 AT&T UNIXAn open() function call appeared in Version 6 AT&T UNIX

What the function returnsWhen

something interesting/ba

d happensRelated man pages

Standards etc.

Page 40: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

The difference between The difference between system and library functionsystem and library function

OS functionLibrary function

Lowest level interfaceUsually calls OS function

Section 2 of man Section 3 of man

System dependent and may not exist on different systems (or used with different name or parameters)

Programming language dependent (but not system dependent)

Almost always bug freeAlmost always bugfree

Almost always efficientAlmost always efficient

Usually – kernel space codeUsually - user space code

Page 41: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

fopen(3) fopen(3) implementationimplementation

    FILE *fopen(char *name, char *mode)FILE *fopen(char *name, char *mode)

{{       int fd;       int fd;       FILE *fp;       FILE *fp;

  if (*mode != ‘r’ && *mode != ‘w’ && *mode != ‘a’)if (*mode != ‘r’ && *mode != ‘w’ && *mode != ‘a’)           return NULL;           return NULL;       for (fp = _iob; fp < _iob + OPEN_MAX; fp++)       for (fp = _iob; fp < _iob + OPEN_MAX; fp++)           if ((fp->flag & (_READ | _WRITE)) == 0)           if ((fp->flag & (_READ | _WRITE)) == 0)               break;        /* found free slot */               break;        /* found free slot */       if (fp >= _iob + OPEN_MAX)   /* no free slots */       if (fp >= _iob + OPEN_MAX)   /* no free slots */           return NULL;           return NULL;

              if (*mode == ‘w’)if (*mode == ‘w’)           fd = creat(name, PERMS);           fd = creat(name, PERMS);       else if (*mode == ‘a’) {       else if (*mode == ‘a’) {           if ((fd = open(name, O_WRONLY, 0)) == -1)           if ((fd = open(name, O_WRONLY, 0)) == -1)               fd = creat(name, PERMS);               fd = creat(name, PERMS);           lseek(fd, 0L, 2);           lseek(fd, 0L, 2);       } else       } else           fd = open(name, O_RDONLY, 0);           fd = open(name, O_RDONLY, 0);       if (fd == -1)         /* couldn’t access name */       if (fd == -1)         /* couldn’t access name */           return NULL;           return NULL;       fp->fd = fd;       fp->fd = fd;       fp->cnt = 0;       fp->cnt = 0;       fp->base = NULL;       fp->base = NULL;       fp->flag = (*mode == ‘r’) ? _READ : _WRITE;       fp->flag = (*mode == ‘r’) ? _READ : _WRITE;       return fp;       return fp;

}}

System calls!

Page 42: OS course – lecture 1 Nezer J. Zaidenberg. Announcements Lecturer : Prof. Amir Averbuch Lecturer : Prof. Amir Averbuch Tutoring assistant :Mr. Nezer Zaidenberg

Conclusion

So OS code is the underlying layer of the library function

Homework – (not for submission) Examine printf(3) code – find the OS function

call references. Follow all functions printf calls!