Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 350 System Programming

Similar presentations


Presentation on theme: "COSC 350 System Programming"— Presentation transcript:

1 COSC 350 System Programming
Dr. Xiaohong (Sophie) Wang Department of Mathematics & Computer Science Office: HS122 Phone: (410)

2 Course Outline UNIX/Linux basics & programming in Linux
Working with files Terminals Processes IPC with signals and pipes Socket programming Perl programming (time permit)

3 Course Syllabus http://faculty.salisbury.edu/~xswang/
Courses/Csc350/cosc350.htm

4 0. Introduction Two kinds of computer software: System programs:
manage the operation of the computer itself (operating systems, device drivers, etc) Application programs: solve problems for the computer users (compilers, editors, word processors)

5 What is Operating System?
System program that controls all the computer’s resources and provides the base on which the application programs can be written. As an extended machines Present user with the equivalent of an extended machine that is easier to program than the underlying hardware As a resource manager Keep track of who is using which resource, to grant resource, to account for usage, and to mediate conflicting requests from different programs and users.

6 System calls A set of instructions provided by the operating system as the interface between the operating system and the user programs.

7 Kinds of system calls: File and directory management
Process management Signaling Protection Time management

8 Organization of the OS GUI, Shell programming shell Kernel

9 Organization of the OS Kernel Shell
Interacts with the hardware (know about devices, file structure, etc) Is built for a specific piece of hardware Has only a few user-level commands such as cp, mv, rm and file creation and manipulation Shell A program runs by the kernel Accepts user commands and presents them to the kernel Many varieties

10 Shell can work in Interactive mode Shell scripts Display prompt
Read command Interpret command Execute command Shell scripts Write all shell commands into an executable file Run the executable file within the shell

11 History and Evolution of UNIX
at Bell lab by Thompson & Ritchie in 1969 Two basic varieties: 4.3+BDS System V Release 4 Other vendors: IBM AIX Sun Solaris HP HP-UX SCO Unixware

12 Ideas behind UNIX Multi-users and multi-processes
time slicing foreground and background Hierarchical directory structure (tree structure) Large number of small tools

13 UNIX Philosophy Simplicity Focus Reusable components Filters
Open file format Flexibility

14 What is Linux? A freely distributed implementation of a UNIX-like kernel Low-level core of an operating system Similar to UNIX Initially developed by Linus Torvalds at University of Helsinki Developers from across the Internet

15 Programming Linux Linux programs (executables and scripts)
The C compiler - gcc Library files Static libraries Shared libraries Getting help man page info

16 Libraries Collections of precompiled functions
Standard system libraries are usually stored in /lib or /usr/lib A library file name starts with lib followed by what library this is (e.g., libc for c library, or libm for mathematical library) The last part of the name is .a for traditional, static libraries .so for shared libraries Compiler needs to be told which library to look for $gcc –o fred fred.c /usr/lib/libm.a $gcc –o fred fred.c –lm $gcc –o x11fred –L/usr/openwin/lib x11fred.c –lX11

17 Static libraries Collection of object files kept together
To use those functions, include the header file The compiler and linker take care of combining the program code and library into a single executable -l is needed to indicate which libraries other than standard C library

18 Try it out - Static libraries
Create source files #include <stdio.h> void fred(int arg) { printf("fred: you passed %d\n", arg); } void bill(char *arg) printf("bill: you passed %s\n", arg);

19 Compile those functions
%gcc –c bill.c fred.c %ls *.o Header file for the library /* This is lib.h. It declares the functions fred and bill for users */ void bill(char *); void fred(int);

20 The calling program (program.c)
#include "lib.h" int main() { bill("Hello World"); exit(0); } Compile the program %gcc –c program.c %gcc –o program program.o bill.o %./program Bill: you passed Hello World %

21 Create the library %ar crv libfoo.a bill.o fred.o a - bill.o a - fred.o Some systems (Berkeley UNIX) requires to create the table of content for the library (under Linux is not necessary) %ranlib libfoo.a To use the library %gcc –o program program.o –L. -lfoo

22 Shared libraries Problem with static library – many copies of the same function in the memory and disk space. When shared library is used, it is not included in the calling program. A reference to the library is made available to the calling program at run time. When the calling program is loaded for execution, the reference is resolved and calls made to the shared library, which is loaded into memory if needed. To see which shared libraries are required by a program $ldd program libc.so.6 => /lib/libc.so.6(0x4002a000) /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x )

23 Getting help On-line manual page On-line documentation system $man gcc
$info gcc


Download ppt "COSC 350 System Programming"

Similar presentations


Ads by Google