Lecture 17. Process Management. Process Management. Process Management. Inter-Process Communication. Inter-Process Communication



Similar documents
Implementing Network Software

System calls. Problem: How to access resources other than CPU

NS3 Lab 1 TCP/IP Network Programming in C

Socket Programming. Srinidhi Varadarajan

Socket Programming. Kameswari Chebrolu Dept. of Electrical Engineering, IIT Kanpur

Overview. Socket Programming. Using Ports to Identify Services. UNIX Socket API. Knowing What Port Number To Use. Socket: End Point of Communication

Tutorial on Socket Programming

LOW LEVEL FILE PROCESSING

Introduction to Socket programming using C

Unix Network Programming

System Calls Related to File Manipulation

Network Communication

How To Write On A Non-Blocking File On A Thumbtongue (Windows) (Windows 2) (Macintosh) (Amd64) (Apple) (Powerpoint) (Networking) (Unix) (Program) (

Writing a C-based Client/Server

TCP/IP - Socket Programming

System Calls and Standard I/O

BSD Sockets Interface Programmer s Guide

Lab 4: Socket Programming: netcat part

Computer Networks Network architecture

Introduction to Socket Programming Part I : TCP Clients, Servers; Host information

Network Programming with Sockets. Process Management in UNIX

Session NM059. TCP/IP Programming on VMS. Geoff Bryant Process Software

TFTP Usage and Design. Diskless Workstation Booting 1. TFTP Usage and Design (cont.) CSCE 515: Computer Network Programming TFTP + Errors

Socket = an interface connection between two (dissimilar) pipes. OS provides this API to connect applications to networks. home.comcast.

Socket Programming. Request. Reply. Figure 1. Client-Server paradigm

Network Programming TDC 561

Application Architecture

Socket Programming in C/C++

Networks. Inter-process Communication. Pipes. Inter-process Communication

Unix System Calls. Dept. CSIE

Network Programming with Sockets. Anatomy of an Internet Connection

Best practices in IPv6 enabled networking software development.

KATRAGADDA INNOVATIVE TRUST FOR EDUCATION NETWORK PROGRAMMING. Notes prepared by D. Teja Santosh, Assistant Professor, KPES, Shabad, R.R. District.

INTRODUCTION UNIX NETWORK PROGRAMMING Vol 1, Third Edition by Richard Stevens

The POSIX Socket API

Lecture 24 Systems Programming in C

Networks and Protocols Course: International University Bremen Date: Dr. Jürgen Schönwälder Deadline:

Packet Sniffing and Spoofing Lab

OS: IPC I. Cooperating Processes. CIT 595 Spring Message Passing vs. Shared Memory. Message Passing: Unix Pipes

ELEN 602: Computer Communications and Networking. Socket Programming Basics

Porting applications & DNS issues. socket interface extensions for IPv6. Eva M. Castro. ecastro@dit.upm.es. dit. Porting applications & DNS issues UPM

IT304 Experiment 2 To understand the concept of IPC, Pipes, Signals, Multi-Threading and Multiprocessing in the context of networking.

Communication Networks. Introduction & Socket Programming Yuval Rochman

ICT SEcurity BASICS. Course: Software Defined Radio. Angelo Liguori. SP4TE lab.

Programmation Systèmes Cours 9 UNIX Domain Sockets

Implementing and testing tftp

Networks class CS144 Introduction to Computer Networking Goal: Teach the concepts underlying networks Prerequisites:

Division of Informatics, University of Edinburgh

µtasker Document FTP Client

1 Posix API vs Windows API

Java Network. Slides prepared by : Farzana Rahman

UNIX Sockets. COS 461 Precept 1

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

Lecture 7: Java RMI. CS178: Programming Parallel and Distributed Systems. February 14, 2001 Steven P. Reiss

Shared file. LINUX Virtual File System. Hard link. Linux ext2fs. Disk layout in general. Linux: ext2fs & ext3fs, Windows NTFS Distributed Processing

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

Concurrent Server Design Alternatives

CS 213, Fall 2000 Lab Assignment L5: Logging Web Proxy Assigned: Nov. 28, Due: Mon. Dec. 11, 11:59PM

SSL/TLS Programming. sslclient.c. /* A simple SSL client. It connects and then forwards data from/to the terminal to/from the server */

Shared Memory Segments and POSIX Semaphores 1

Shared Memory Introduction

Java Programming: Sockets in Java

Direct Sockets. Christian Leber Lehrstuhl Rechnerarchitektur Universität Mannheim

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

Process definition Concurrency Process status Process attributes PROCESES 1.3

Operating Systems. Privileged Instructions

Network programming, DNS, and NAT. Copyright University of Illinois CS 241 Staff 1

CSE 333 SECTION 6. Networking and sockets

Application Development with TCP/IP. Brian S. Mitchell Drexel University

Generalised Socket Addresses for Unix Squeak

What is CSG150 about? Fundamentals of Computer Networking. Course Outline. Lecture 1 Outline. Guevara Noubir noubir@ccs.neu.

VMCI Sockets Programming Guide VMware ESX/ESXi 4.x VMware Workstation 7.x VMware Server 2.0

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

COMMMUNICATING COOPERATING PROCESSES

Network Programming. Writing network and internet applications.

Chapter I/O and File System

CS162 Operating Systems and Systems Programming Lecture 4. Introduction to I/O (Continued), Sockets, Networking. Recall: Fork and Wait

Elementary Name and Address. Conversions

Illustration 1: Diagram of program function and data flow

DESIGN AND IMPLEMENT AND ONLINE EXERCISE FOR TEACHING AND DEVELOPMENT OF A SERVER USING SOCKET PROGRAMMING IN C

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring HDFS Basics

An Advanced 4.4BSD Interprocess Communication Tutorial

File Transfer And Access (FTP, TFTP, NFS) Chapter 25 By: Sang Oh Spencer Kam Atsuya Takagi

OCS Training Workshop LAB14. Setup

How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

Chapter 2: Remote Procedure Call (RPC)

IBM i Version 7.2. Programming Socket programming IBM

Operating Systems Design 16. Networking: Sockets

Writing Client/Server Programs in C Using Sockets (A Tutorial) Part I. Session Greg Granger grgran@sas. sas.com. SAS/C & C++ Support

Lecture 9: Network Security Introduction

5. Processes and Memory Management

Transport layer protocols. Message destination: Socket +Port. Asynchronous vs. Synchronous. Operations of Request-Reply. Sockets

Introduction. dnotify

NetFlow Aggregation. Feature Overview. Aggregation Cache Schemes

UNIX. Sockets. mgr inż. Marcin Borkowski

Transcription:

Process Management Lecture 17 Review February 25, 2005 Program? Process? Thread? Disadvantages, advantages of threads? How do you identify processes? How do you fork a child process, the child process does some work, while parent process waits? Process Management Program? Process? Thread? Disadvantages, advantages of threads? How do you identify processes? How do you fork a child process, the child process does some work, while parent process waits? if (pid < 0) {exit(1); if (pid == 0) { /* child */ else { /* parent: wait/waitpid */ Process Management What does exec* do? What is a zombie process? Inter-Process Communication Why are pipes and fork() typically used together? Inter-Process Communication Why are pipes and fork() typically used together? fd[1] fd[0] What if you want to talk in both directions? 1

Shared Memory shmget-shmat-shmdt-shmctl key + IPC_CREAT SHM_RDONLY Race Condition int add_element(int element) { if (index == 32) return -1; array[index] = element; index = index + 1; return (index); Semaphores: UP, DOWN? Mutual exclusion, critical sections? Possible problem: solve race condition in code above... Condition Variables void *handler_fct(void *arg) { // handle client pthread_mutex_lock(&at_mutex); active_threads--; pthread_cond_signal(&at_cond); pthread_mutex_unlock(&at_mutex); return(); Condition Variables active_threads = 0; while (1) { pthread_mutex_lock(&at_mutex); while (active_threads < n) { active_threads++; pthread_start(...); pthread_cond_wait(&at_cond, &at_mutex); pthread_mutex_unlock(&at_mutex); OSI Reference Model Layered model: 7. Application 6. Presentation 5. Session 4. Transport 3. Network 2. Data Link 1. Physical OSI Reference Model Layered model: 7. Application 6. Presentation 5. Session 4. Transport 3. Network 2. Data Link 1. Physical Where does UDP/TCP belong to? Ethernet? Bluetooth? IEEE 802.11abg? HTTP? IP? 2

UDP versus TCP versus IP IP offers no guarantee: packets may get lost. packets may be delivered twice. packets may be delivered in the wrong order. packets may be corrupted during transfer. UDP is very similar to IP: send/receive packets, no guarantee. packets are called datagrams. TCP: reliable, data flow, timeouts, ordered, error detection... File I/O What does blocking/non-blocking mean? fd = open(pathname, flags, [mode]); what s the flag for reading only? what if I want to append data at the end of the file? what if I do not want to open it if it already exists? File I/O What does blocking/non-blocking mean? fd = open(pathname, flags, [mode]); what s the flag for reading only? O_RDONLY what if I want to append data at the end of the file? O_APPEND what if I do not want to open it if it already exists? O_EXCL (together with O_CREAT) Positioning off_t lseek(int fd, off_t offset, int whence); SEEK_SET SEEK_CUR SEEK_END File Permissions permission bits: r,x,w r: read w: write x: execute Files drwxrwxrwx 4 cpoellab team1 122 Dec 12 18:02 Assignments Pos: 1 2 3 4 5 6 7 8 9 10 -dl r w x r w x r w x 3

Files What is umask used for? drwxrwxrwx 4 cpoellab team1 122 Dec 12 18:02 Assignments type and permission (drwxrwxrwx) number of links: 4 owner: cpoellab file s group: team1 size in bytes (122) date of last modification (Dec 12 18:02) filename: Assignments Type: d = directory l = symbolic link s = socket p = named pipe - = regular file c = character special file b = block special file Set and determine the default file creation permissions on the system: 777 - executable files 666 - text files Permission for creation of new executable is calculated by subtracting the umask value: 666-022=644 umask 022 /etc/profile Client-Server SERVER socket() bind() listen() accept() read() write() blocks until connection from client connection establishment process request data request data reply CLIENT socket() connect() write() read() TCP Client #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <string.h> #include <unistd.h> #include <stdlib.h> #include <stdio.h> extern struct in_addr host2ip (char *host); int main(int argc, char *argv[]) { int s, n; struct sockaddr_in sin; char msg[80] = Hello, World! ; if ((s = socket(pf_inet, SOCK_STREAM, 0)) < 0) { perror( socket ); return(-1); TCP Server TCP Server int main(int argc, char *argv[]) { int s, t, n; struct sockaddr_in sin; char *r; int sinlen; if ((s = socket(pf_inet, SOCK_STREAM, 0)) < 0) { perror( socket); return -1; sin.sin_family = AF_INET; sin.sin_port = htons(13333); sin.sin_addr.s_addr = INADDR_ANY; if (bind (s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { perror( bind ); return -1; if (listen(s, 5) < 0) { perror( listen ); return -1; for (;;) { sinlen = sizeof(sin); if ((t = accept(s, (struct sockaddr *) &sin, &sinlen)) < 0) { perror( accept ); return -1; r = gettime(); if (write(t, r, strlen(r)) < 0) { perror ( write ); return -1; if (close(t) < 0) { perror( close ); return -1; if (close(s) < 0) { perror( close ); return -1; 4

Iterative vs Concurrent Iterative servers: process one request at a time. Concurrent server: process multiple requests simultaneously. Concurrent: better use of resources (service others while waiting) and incoming requests can start being processed immediately after reception. Multi-threaded approach void sig_chld(int) { while (waitpid(0, NULL, WNOHANG) > 0) { signal(sigchld, sig_chld); int main() { int fd, newfd, pid; signal(sigchld, sig_chld); while (1) { newfd = accept(fd,...); if (newfd < 0) continue; pid = fork(); if (pid == 0) { handle_request(newfd); exit(0); else {close(newfd); Process Pools #define NB_PROC 10 void recv_requests(int fd) { int f; while (1) { f = accept(fd,...); handle_request(f); close(f); int main() { int fd; for (int i=0; i<nb_proc; i++) { if (fork() == 0) recv_requests(fd); while (1) pause(); select() int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); nfds: highest number assigned to a descriptor. block until >=1 file descriptors have something to be read, written, or timeout. set bit mask for descriptors to watch using FD_SET. returns with bits for ready descriptor set: check with FD_ISSET. cannot specify amount of data ready. fd_set void FD_ZERO(fd_set *fdset); void FD_SET(int fd, fd_set *fdset); void FD_CLR(int fd, fd_set *fdset); int FD_ISSET(int fd, fd_set *fdset); Why inetd/xinetd Separation of master server and actual services. Allows separate maintenance or replacement without recompilation. Called super server. Services can easily be added/removed/replaced. Static configuration: when server starts up (file: services + executable programs), changes require restart. Dynamic configuration: same as above but admin can notify server of changes (e.g., signals), no restart required. 5

hostent RPC Multiple addresses possible. h_addr: for compatibility, refers to first location in the host address list. struct hostent *host; char *thishostname = wizard.cse.nd.edu ; if (host = gethostbyname(thishostname)) { /* access address in host->h_addr */ else { /* error handling */ memcpy((char*)&sa.sin_addr, (char*)host->h_addr, host->h_length); main() stub(12); return 5; stub Request Reply skeleton func(12); return 5; func() Client Server RPC Specification.x file client.c add.x add_clnt.c add.h add_xdr.c client.o add_clnt.o add_xdr.o client Step 1: Write a specification file (add.x) struct add_in { /* Arguments of procedure */ long arg1; long arg2; ; typedef long add_out; /* Return value */ serverproc.c You write these files add_scv.c rpcgen generates these files add_svc.o serverproc.o You compile every C file server You obtain a client & server program ADD_PROG { version ADD_VERS { add_out ADD_PROC(add_in) = 1 /* Procedure# = 1 */ = 1; /* Version# = 1 */ = 0x3434000; /* Program# = 0x3434000 */ RPC RMI Purpose of port mapper? Purpose of XDR? How do you indicate direction of conversion? What s the buffer paradigm? Client Client Remote Object Interface Stub Server Remote Object Implementation Remote Object Interface Skeleton You implement this RMI implements this 6

Interface More Questions? Step 1: write interface Calculator.java import java.rmi.remote; import java.rmi.remoteexception; public interface Calculator extends Remote { public long add(long a, long b) throws RemoteException; public long sub(long a, long b) throws RemoteException; public long mul(long a, long b) throws RemoteException; public long div(long a, long b) throws RemoteException; Good Luck! 7