LiiS:CorsiPSR

Da Wikipedia, l'enciclopedia libera.

Contents

System and Network Programming

Year: First of a 2nd level degree course (two years)
Semester: second
Credits: 9
Degree name: Computer Engineering

Teacher

Prof. Franco Tommasi

Course aims and objectives

The course aims at teaching system and network programming for a real world operating system. The selected operating system is UNIX, in its Linux and BSD (MacOS X) versions.

Most system calls are presented and thoroughly practiced.

Prerequisites

Knowledge of the C programming language (a good reading skill at the very least). Attendance at the Corso di Sistemi Operativi (second year of the 1st level degree course "Ingegneria dell'Informazione", held from the same teacher) is strongly suggested.

Course content

Chapters and paragraphs from

W. Richard Stevens, Stephen A. Rago "Advanced Programming in the UNIX® Environment - Third Edition":

Chapter 1. UNIX System Overview

1.1 Introduction

1.2 UNIX Architecture

1.3 Logging In

1.4 Files and Directories

1.5 Input and Output

1.6 Programs and Processes

1.7 Error Handling

1.8 User Identification

1.9 Signals

1.10 Time Values

1.11 System Calls and Library Functions

1.12 Summary


Chapter 2. UNIX Standardization and Implementations

2.1 Introduction

2.2 UNIX Standardization

2.2.1 ISO C

2.2.2 IEEE POSIX

2.2.3 The Single UNIX Specification

2.3 UNIX System Implementations

2.3.1 UNIX System V Release 4

2.3.2 4.4BSD

2.3.3 FreeBSD

2.3.4 Linux

2.3.5 Mac OS X

2.4 Relationship of Standards and Implementations

2.5 Limits

2.5.1 ISO C Limits

2.5.2 POSIX Limits

2.5.3 XSI Limits

2.5.4 sysconf, pathconf, and fpathconf Functions

2.5.5 Indeterminate Runtime Limits

2.6 Options

2.7 Feature Test Macros

2.8 Primitive System Data Types

2.9 Differences Between Standards

2.10 Summary


Chapter 3. File I/O

3.1 Introduction

3.2 File Descriptors

3.3 open and openat Functions

3.4 creat Function

3.5 close Function

3.6 lseek Function

3.7 read Function

3.8 write Function

3.9 I/O Efficiency

3.10 File Sharing

3.11 Atomic Operations

3.12 dup and dup2[…]

3.13 sync, fsync, and fdatasync Functions

3.14 fcntl Function

3.15 ioctl Function

3.16 /dev/fd

3.17 Summary


Chapter 4. Files and Directories


4.1 Introduction

4.2 stat, fstat, fstatat, and lstat Functions

4.3 File Types

4.4 Set-User-ID and Set-Group-ID

4.5 File Access Permissions

4.6 Ownership of New Files and Directories

4.7 access and faccessat Functions

4.8 umask Function

4.9 chmod, fchmod, and fchmodat Functions

4.10 Sticky Bit

4.11 chown, fchown, fchownat, and lchown Functions

4.12 File Size

4.13 File Truncation

4.14 File Systems

4.15 link, linkat, unlink, unlinkat, and remove Functions

4.16 rename and renameat Functions

4.17 Symbolic Links

4.18 Creating and Reading Symbolic Links

4.19 File Times

4.20 futimens, utimensat, and utimes Functions

4.21 mkdir, mkdirat, and rmdir Functions

4.22 Reading Directories

4.23 chdir, fchdir, and getcwd Functions

4.24 Device Special Files

4.25 Summary of File Access Permission Bits

4.26 Summary


Chapter 6. System Data Files and Information

6.1 Introduction

6.2 Password File

6.3 Shadow Passwords

6.4 Group File

6.5 Supplementary Group IDs

6.6 Implementation Differences

6.7 Other Data Files

6.8 Login Accounting

6.9 System Identification

6.10 Time and Date Routines

6.11 Summary


Chapter 7. Process Environment

7.1 Introduction

7.2 main Function

7.3 Process Termination

7.4 Command-Line Arguments

7.5 Environment List

7.6 Memory Layout of a C Program

7.7 Shared Libraries

7.8 Memory Allocation

7.9 Environment Variables

7.11 getrlimit and setrlimit Functions

7.12 Summary


Chapter 8. Process Control

8.1 Introduction

8.2 Process Identifiers

8.3 fork Function

8.5 exit Functions

8.6 wait and waitpid Functions

8.7 waitid Function

8.8 wait3 and wait4 Functions

8.9 Race Conditions

8.10 exec Functions

8.11 Changing User IDs and Group IDs

8.12 Interpreter Files

8.13 system Function

8.14 Process Accounting

8.15 User Identification

8.16 Process Scheduling

8.17 Process Times

8.18 Summary


Chapter 9. Process Relationships

9.1 Introduction

9.2 Terminal Logins

9.3 Network Logins

9.4 Process Groups

9.5 Sessions

9.6 Controlling Terminal

9.7 tcgetpgrp, tcsetpgrp, and tcgetsid Functions

9.8 Job Control

9.9 Shell Execution of Programs

9.10 Orphaned Process Groups

9.11 FreeBSD Implementation

9.12 Summary


Chapter 10. Signals

10.1 Introduction

10.2 Signal Concepts

10.3 signal Function

10.4 Unreliable Signals

10.5 Interrupted System Calls

10.6 Reentrant Functions

10.7 SIGCLD Semantics

10.8 Reliable-Signal Terminology and Semantics

10.9 kill and raise Functions

10.10 alarm and pause Functions

10.11 Signal Sets

10.12 sigprocmask Function

10.13 sigpending Function

10.14 sigaction Function

10.16 sigsuspend Function

10.17 abort Function

10.18 system Function

10.19 sleep, nanosleep, and clock_nanosleep Functions

10.20 sigqueue Function

10.21 Job-Control Signals

10.22 Signal Names and Numbers

10.23 Summary


Chapter 11. Threads

11.1 Introduction

11.2 Thread Concepts

11.3 Thread Identification

11.4 Thread Creation

11.5 Thread Termination

11.6 Thread Synchronization

11.6.1 Mutexes

11.6.2 Deadlock Avoidance

11.6.3 pthread_mutex_timedlock Function

11.6.4 Reader–Writer Locks

11.6.5 Reader–Writer Locking with Timeouts

11.6.6 Condition Variables

11.7 Summary


Chapter 12. Thread Control

12.1 Introduction

12.2 Thread Limits

12.3 Thread Attributes

12.4 Synchronization Attributes

12.4.1 Mutex Attributes

12.4.2 Reader–Writer Lock Attributes

12.4.3 Condition Variable Attributes

12.4.4 Barrier Attributes

12.5 Reentrancy

12.6 Thread-Specific Data

12.7 Cancel Options

12.8 Threads and Signals

12.9 Threads and fork

12.10 Threads and I/O

12.11 Summary


Chapter 13. Daemon Processes

13.1 Introduction

13.2 Daemon Characteristics

13.3 Coding Rules

13.4 Error Logging

13.5 Single-Instance Daemons

13.6 Daemon Conventions

13.7 Client–Server Model


13.8 Summary

Chapter 14. Advanced I/O

14.1 Introduction

14.2 Nonblocking I/O

14.3 Record Locking

14.4 I/O Multiplexing

14.4.1 select and pselect Functions

14.4.2 poll Function

14.5 Asynchronous I/O

14.5.1 System V Asynchronous I/O

14.5.2 BSD Asynchronous I/O

14.5.3 POSIX Asynchronous I/O

14.6 readv and writev Functions

14.7 readn and writen Functions

14.8 Memory-Mapped I/O

14.9 Summary


Chapter 15. Interprocess Communication

15.1 Introduction

15.2 Pipes

15.3 popen and pclose Functions

15.4 Coprocesses

15.5 FIFOs

15.6 XSI IPC

15.6.1 Identifiers and keys

15.6.2 Permission Structure

15.6.3 Configuration Limits

15.6.4 Advantages and Disadvantages

15.7 Message Queues

15.8 Semaphores

15.9 Shared Memory

15.10 POSIX Semaphores

15.11 Client–Server Properties

15.12 Summary


Chapter 16. Network IPC: Sockets

16.1 Introduction

16.2 Socket Descriptors

16.3 Addressing

16.3.1 Byte Ordering

16.3.2 Address Formats

16.3.3 Address Lookup

16.3.4 Associating Addresses with Sockets

16.4 Connection Establishment

16.5 Data Transfer

16.6 Socket Options

16.7 Out-of-Band Data

16.8 Nonblocking and Asynchronous I/O

16.9 Summary


A more detailed list of the network sockets topics treated in the program

- intro to bsd socket api

- posix def: struct sockaddr, struct sockaddr_in, struct sockaddr_in6, struct sockaddr_storage

- endianness: ntoh(s/l), hton(s/l)

- inet_pton(), inet_ntop()

- def socket

- TCP client-server: socket(), bind(), listen(), accept(), connect(), send(), recv(), close()

- getpeername(), getsockname()

- tcp client-server basic example

- UDP client-server: sendto(), recvfrom() - socket UDP (connection mode) Examples:

- udp client-server basic

- Connected udp server

- tcp client-server managing missing message boundaries

- Hostname resolution: DNS e resolver, getaddrinfo(), freeaddrinfo() - getaddrinfo examples

- TCP client server with hostname resolution

- UDP client server with hostname resolution

- UDP client: concetto socket with asynchronous errors

- socket options

- Closing a TCP connection (shutdown vs close vs SO_LINGER) non-blocking mode for sockets

- Non-blocking sockets

- I/O flag (non-blocking connect)

- broadcast and multicast

- IPv4-IPv6 interoperability

- Example code

Suggested texts and readings

W. Richard Stevens, Stephen A. Rago "Advanced Programming in the UNIX® Environment - Third Edition"

Stevens, Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition), 2003

Kerrisk, The Linux Programming Interface: A Linux and UNIX System Programming Handbook, 2010

Piccardi, Guida alla Programmazione in Linux, 2011 (free text from http://gapil.gnulinux.it/files/2011/12/gapil.pdf)

A good C Language manual is strongly suggested

Very useful are also Single UNIX Specification version 4 e la Linux Standard Base.

Teaching materials

All teaching materials are available in the course moodle site http://moodliis.unisalento.it (credentials required)


Final test procedures

A practical programming exercise about the course program will be proposed to the students. They will have to write a working program within the assigned time (usually two or three hours).

Personal tools
Consiglio Didattico