You are on page 1of 24

SYSTEM

PROGRAMMING
LECTURE # 1
INTRODUCTION TO SYSTEM PROGRAMMING

Course Code: CS 312


Course Instructor: Dr. Sarah Iqbal

1
COURSE INFO. & LECTURE SCHEDULE

 Course Pre-Requisite: CS311 Introduction to Operating Systems


Familiar with Linux Command Interpreter
C Programming

 Credit Hours: 3 Hrs.


 Lecture Time and Venue: Monday 12:30 – 13:20 CS LH1
Wednesday 10:30 – 11:20 CS LH1
Friday 10:00 – 10:50 CS LH1

 Instructor: Dr. Sarah Iqbal


Office: G-12 FCSE Lobby, GIK Institute
sarah.iqbal@giki.edu.pk 2
INSTRUCTIONS TO FOLLOW DURING CLASS

 Switch off/Silent your cell phones during the classroom.


 Strictly follow the lecture schedule issued by the faculty.
 According to institute policy, 80% attendance is mandatory to
appear in the final examination.
 Assignments must be submitted as per instructions.
 There will be no retake of (scheduled/surprise) quizzes.
 For queries, kindly contact the instructor to avoid inconvenience.
 Must act according to GIKI’s code of conduct.

3
GRADING POLICY

Assessment Item Percentage (%)


Quizzes, Assignments & Presentations 30 %
Mid Exam 30 %
Final Exam 40 %
Total 100 %

4
TEXT & REFERENCE BOOKS

 Beginning Linux Programming (4th Ed) by Mathew and Stones,


Wiley Publishing, Inc.
 Unix Systems Programming: Communication, Concurrency and
Thread (2nd Ed) by Robbins and Robbins, Prentice Hall.
 The Linux Programming Interface: A Linux and UNIX System
Programming Handbook by Michael Kerrisk (2010)
 Linux System Programming: Talking Directly to the Kernel and C
Library by Robert Love (2013)

5
COURSE INTRODUCTION

This course introduces fundamentals of Linux Operating System and


System calls. Accompanied with a comprehensive foundation, a
hands-on approach in C language shall be used to program with
system calls for variety of tasks ranging from process creation and
management up to inter-process communication over a network.

The objective is to understand and apply different Operating System


services using the Linux Operating System API. After this course you will
be able understand and take courses on Operating System Kernel
development.

6
AGENDA FOR TODAY

 Course Introduction
 Application Programming vs System Programming
 Discussion on course outline

7
WHAT IS SYSTEM PROGRAMMING?

Computer programming can be categorized into two categories:


 Application Programming
 System Programming

Input Process Output

While designing software the programmer may determine the


required inputs for that program (file/keyboard), the wanted
outputs/results and the processing, the software would perform in
order to give those wanted outputs.
8
APPLICATION PROGRAMMING VS
SYSTEM PROGRAMMING

 The implementation of the processing part is associated with application


programming. Application programming facilitates the implementation
of the required processing that software is supposed to perform;
everything that is left now is facilitated by system programming.

 Systems programming is the study of techniques that facilitate the


acquisition of data from input devices, these techniques also facilitates
the output of data which may be the result of processing performed by
an application.

9
A BASIC C PROGRAM

int main()
{
int c;
while ((c = getchar()) != EOF)
putchar(c);
return 0;
}

10
SYSTEM PROGRAMMER PERSPECTIVE
 Many users running multiple programs
 Accessing lots of disk files
 Needs to access different devices
 More and more connections

Who is managing all these resources and


connecting various devices to correct
programs?

11
SYSTEM PROGRAMMER PERSPECTIVE
 The role of Operating System is to
manage all these resources and to
connect various devices to the correct
programs.
 Operating System Kernel act as a
resource manager and facilitates the
process or user by avoiding a direct
hardware access.

12
APPLICATION PROGRAMMING VS
SYSTEM PROGRAMMING

 Application programming aims to produce software which


provides services to the user, e.g., word processors, browsers,
multi-media applications, etc.
 System Programming aims to produce software which provides
services to computer hardware, e.g., disk defragmenter. The next
step is writing kernel code to manage main memory, disk space
management, CPU scheduling, and management of I/O devices
through device drivers.

13
THE CORE OPERATING SYSTEM:
THE KERNEL
The term operating system is commonly used with two different
meanings:
 To denote the entire package consisting of the central software
managing a computer’s resources and all of the accompanying
standard software tools, such as command-line interpreters,
graphical user interfaces, file utilities, and editors.
 More narrowly, to refer to the central software that manages and
allocates computer resources (i.e., the CPU, RAM, and devices).
Although it is possible to run programs on a computer without a kernel,
the presence of a kernel greatly simplifies the writing and use of other
programs, and increases the power and flexibility available to
programmers. The kernel does this by providing a software layer to
manage the limited resources of a computer.

14
TASKS PERFORMED BY THE KERNEL

Among other things, the kernel performs the following tasks:


 Process scheduling
 Memory management
 Provision of a file system
 Creation and termination of processes
 Access to devices
 Networking
 Provision of a system call application programming interface
(API)

15
SYSTEM PROGRAMMING
Executable
Program

Library
Function User Mode

Kernel Mode
System
Call

Printer Functions
Kernel
 printf()
 scanf() Hardware
 fopen()
16
SYSTEM PROGRAMMER PERSPECTIVE

A system programmer write programs that may have to acquire data


 from a file(s) (residing on a local or remote disc) that may have been
opened by some other user(s),
 from other programs running on the same or different machine,
 from the operating system itself.

After processing, the programs may have to write results to a shared


resource, which other processes are also writing, or results may need to
be delivered to another process asynchronously, i.e., not when the
process asked for it, but at some later unpredictable time.
The challenge is to master these concepts.
17
OPERATING SYSTEM SERVICES

Two methods by which a program can make requests for


services from the Kernel:
 Bymaking a system call (entry point built directly into the
kernel)
 Bycalling a library routine that makes use of this system
call

18
SYSTEM CALLS

System call is the controlled entry point into the kernel code, allowing a
process to request the kernel to perform a privileged operation.
Before going into the details of how a system call works, following points
need to be understood:
 A system call changes the processor state from user mode to kernel
mode, so that the CPU can access protected kernel memory
 The set of system calls is fixed. Each system call is identified by a unique
number
 Each system call may have a set of arguments that specify information to
be transferred from user space to kernel space and vice versa

19
SYSTEM CALL INVOCATION
 Basic Calling
sequence of a system
call
 Paths to enter kernel
code are interrupts,
traps, signals and
system calls

20
SYSTEM CALL INVOCATION

21
COURSE OUTLINE
In this course we shall learn to use the services provided by the
kernel using Linux OS API,
 Library Functions vs System Calls
 Basic I/O
 File Information System Calls
 Programs with command line arguments
 Process Management and Scheduling
 UNIX IPC Tools
 IPC Shared Memory
 Thread Management and Synchronization
 Sockets
 Network Programming
22
Reading material:

The Linux Programming interface: A Linux and UNIX® System


Programming Handbook by Michael KerrisK
Chapter 2: FUNDAMENTAL CONCEPTS, Section 2.1

23
THE END

LECTURE # 1

24

You might also like