Download presentation
Presentation is loading. Please wait.
Published byDamian Simpson Modified over 8 years ago
1
August 31, 2010Joris Geurts1 2IN05 Operating Systems Introduction to Linux More information for this course: http://sandpit.win.tue.nl/course/os/
2
August 31, 2010Joris Geurts2 What is Linux?
3
August 31, 2010Joris Geurts3 Linux is a UNIX-like operating system separation between kernel and user mode
4
August 31, 2010Joris Geurts4 characteristics developed in 1970's by Ritchie and Thomson multi user multi tasking
5
August 31, 2010Joris Geurts5 advantages different hardware: IBM, DEC, Intel, ARM simple structure elaborate software tooling command interpreter: the SHELL principles applied in a consequent way
6
August 31, 2010Joris Geurts6 disadvantages cryptic names, e.g.: cat filename cryptic syntax: \ / * $ " ' ` ~ e.g.: grep "*.$1" `pick *.c` | lpr many members of the family, and they differ
7
August 31, 2010Joris Geurts7 Unix family tree
8
August 31, 2010Joris Geurts8 Some Unix characteristics ‘Everything is a file’ –including screen, mouse, hard disk etc. All (system) commands are just applications –including login procedure, file and directory management, –large and powerful set of commands The central role of the shell (command interpreter) –typing rather than clicking Built-in management of different users –multi-tasking and multi-user
9
August 31, 2010Joris Geurts9 Linux take-off
10
August 31, 2010Joris Geurts10 Initial family tree Since then –many different distributions, with different characteristics –specialized versions (real-time, embedded) –powers the Internet
11
August 31, 2010Joris Geurts11 Linux distributions (600+) kernel + libraries + software applications
12
August 31, 2010Joris Geurts12 Linux desktop environments GNOME KDE
13
August 31, 2010Joris Geurts13 Using Linux The setup for this course –VMware Player –Ubuntu Linux –http://sandpit.win.tue.nl/course/os/dist/ Short demonstration –Starting the system –Using the terminal Some small practical assignments –On the next slide –http://sandpit.win.tue.nl/course/os/ (check.html & linux.html)
14
August 31, 2010Joris Geurts14 Command summary Commands (find out their functionality) –ls –mkdir, cp, mv, which, chmod, echo, grep, pwd, cat, ps –man input/output redirect –ls > file –command1 | command2 | command3 –cat /etc/passwd | sort | less –less /etc/passwd editors –kate, gedit, vi –(to be installed) emacs, joe, nano, eclipse
15
August 31, 2010Joris Geurts15 Practical assignments (shell) Startup and login to the system –Username: user Password: user Create a directory in –Your home directory (/home/user/) –The temporary directory (/tmp/) –The root directory (/) Copy the password file to your home directory Search where the ls binary is located –Determine its owner and permissions –Record this information in a file –Take a look at its manual page
16
August 31, 2010Joris Geurts16 Linux documentation Manual pages (from UNIX system) –User commands (sec. 1), system calls (sec. 2), library routines (sec. 3), file formats (sec. 5), management (sec. 8) man itemman bash man section itemman 5 passwd man –k topicman –k copy Info documents (from GNU tools) –Pre-HTML hyperlink documentation system info iteminfo gcc HTML (from www era) –Integrated in Help browsers of Linux distributions khelpcenter & gnome-help &
17
August 31, 2010Joris Geurts17 Development process Single file applications –Call compiler directly or via a shell script Command: gcc –o myapp myapp.c Medium size applications –Create a Makefile Describe dependencies and how to resolve them –Use ‘make’ command to (re)build the application Large or portable applications (not in 2IN05) –Use ‘autoconf’, ‘automake’ and ‘libtool’ –Perform platform detection on the build host –Support for cross compilation Build applications for embedded devices
18
August 31, 2010Joris Geurts18 C programming language Language of the Linux kernel and many of the applications Very low-level – portable assembly (although...) –No memory protection –No garbage collection –No decent string type –Direct memory pointer manipulation High execution performance possible –At the cost of a longer development time
19
August 31, 2010Joris Geurts19 Hello World see http://sandpit.win.tue.nl/course/os/check.html compile and run $ gcc -o helloworld helloworld.c $./helloworld printf printf ("Hello World\n"); printf ("decimal display: %d\n", i); printf ("hexadecimal display: %04x\n", i); debugger…
20
August 31, 2010Joris Geurts20 Debugging with kdbg sudo apt-get install kdbg (only once) gcc -g –Wall –o myapp myapp.c kdbg myapp & –set breakpoints –press Run, Step Over etc. –inspect variables
21
August 31, 2010Joris Geurts21 Example program Read from the file ‘/etc/passwd’ Write the usernames to the file ‘users’ Useful commands: gcc –Wall –o myapp myapp.c man 3 fgets man 5 passwd Note: to run your application, use:./myapp –Otherwise an existing application might be started instead
22
August 31, 2010Joris Geurts22 Example program #include int main(int argc, char *argv[]) { char linebuffer[1024]; FILE *input; FILE *output; /* Open /etc/passwd for reading. */ input = fopen(“/etc/passwd”, …); if (input == NULL) { fprintf(stderr, “Unable to open /etc/passwd for reading\n”); return 1; } See manual of fopen() parse the linebuffer to find the ':' characters /* Open “users” for writing. */ output = fopen(“users”, …); if (output == NULL) { fprintf(stderr, “Unable to open users for writing\n”); return 1; } /* Process the input file line by line */ while (!feof(input) && !ferror(input)) { char *rtn; rtn = fgets(linebuffer, …, …); if (rtn != NULL) {..... …. fprintf(…, “%s\n”, …); } /* Close the files */ fclose(…); }
23
August 31, 2010Joris Geurts23 arrays root:x:0:0:root:/root:/bin/bash linebuffer (a character array) linebuffer[0] contains a 'r' linebuffer[1] contains a 'o', etc.
24
August 31, 2010Joris Geurts24 Practical assignments Install some tooling – sudo apt-get install manpages-dev Example program on the website –Source available at the website: fill in the gaps –Compile and run –Change the makefile: create a debug build, and run with kdbg Extra: use strsep() instead of your own parsing Extra: give a shell command for this task –Use awk, sed or some other tool –Just read the manual pages –It can be done in one line; which approach is the most efficient?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.