CSC 552.201 - Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 15, class 4.

Slides:



Advertisements
Similar presentations
Lab 9 CIS 370 Umass Dartmouth.  A pipe is typically used as a one-way communications channel which couples one related process to another.  UNIX deals.
Advertisements

Unix programming Term: III B.Tech II semester Unit-V II PPT Slides Text Books: (1)unix the ultimate guide by Sumitabha Das (2)Advanced programming.
NCHU System & Network Lab Lab 15 Record Locking. NCHU System & Network Lab Record Locking (1/4) What happens when two process attempt to edit the same.
Daemon Processes Long lived utility processes Often started at system boot and ended when system shuts down Run in the background with no controlling terminal.
Lesson 10-Controlling User Processes. Overview Managing and processing processes. Managing jobs. Exiting/quitting when jobs have been stopped.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
OS Project #2:Random File Access  Random file access: using the lseek() system call to access files in UNIX. zTake arguments from the command line. 
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
TDC368 UNIX and Network Programming Camelia Zlatea, PhD Week 6:  Inter-Process Synchronization  Signals.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
Daemon Processes and inetd Superserver
CSE 451 Section 4 Project 2 Design Considerations.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
1 Overview Assignment 12: hints  Distributed file systems Assignment 11: solution  File systems.
Lecture 3  Shell Variables  Shell Command History  Job / Process Control  Directory Control.
Server Design Discuss Design issues for Servers Review Server Creation in Linux.
Shell (Part 1). Process r A process is an instance of an application running r If there are two instances of an application running then there are two.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Agenda  Terminal Handling in Unix File Descriptors Opening/Assigning & Closing Sockets Types of Sockets – Internal(Local) vs. Network(Internet) Programming.
Elementary TCP Sockets
Adv. UNIX: lowIO/161 Advanced UNIX v Objectives –look at low-level operations for handling files Special Topics in Comp. Eng. 2 Semester.
Introduction to UNIX / Linux - 11
Unix Pipes Pipe sets up communication channel between two (related) processes. 37 Two processes connected by a pipe.
Simple Shell Part 1 Due date (75%): April, 2002 Part 2 Due date (25%): Apr 5, 2002.
Fundamentals CIS 552. Fundamentals Low-level I/O (read/write using system calls)  Opening/Creating files  Reading & Writing files  Moving around in.
An Introduction to Unix Shell Scripting
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
Cli/Serv.: procs/51 Client/Server Distributed Systems v Objectives –look at how to program UNIX processes , Semester 1, Processes.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Shell (Part 2). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Minishell InKwan Yu Topics Unix System calls waitpid() pipe() dup2() C function calls strtok() strcmp() Minishell Software Enginnering.
System Commands and Interprocess Communication. chroot int chroot(const char *path); chroot changes the root directory to that specified in path. This.
1 System Programming Chapter 3 File I/O. 2 Announcement The first exercise is due today. We will NOT accept late assignment this time. –Submission site.
Agenda  Redirection: Purpose Redirection Facts How to redirecting stdin, stdout, stderr in a program  Pipes: Using Pipes Named Pipes.
Shell (Addendum). Example r What if we want to support something like this: m ps –le | sort r One process should execute ps –le and another should execute.
Chapter Four I/O Redirection1 System Programming Shell Operators.
Project 6 Unix File System. Administrative No Design Review – A design document instead 2-3 pages max No collaboration with peers – Piazza is for clarifications.
1 Daemons & inetd Refs: Chapter Daemons A daemon is a process that: –runs in the background –not associated with any terminal Unix systems typically.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Interprocess Communication Anonymous Pipes Named Pipes (FIFOs) popen() / pclose()
CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 22, class 5.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Recitation: Signaling S04, Recitation, Section A Debug Multiple Processes using GDB Debug Multiple Processes using GDB Dup2 Dup2 Signaling Signaling.
Laface 2007 File system 3.1 Operating System Design Other filesystem system calls pipe dup mount umount link unlink system popen.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 9 Acknowledgements: The syllabus and power point presentations are modified versions.
Interprocess Communication. Resource Sharing –Kernel: Data structures, Buffers –Processes: Shared Memory, Files Synchronization Methods –Kernel: Wait.
January 7, 2003Serguei Mokhov, 1 File I/O System Calls Reference COMP 229, 444, 5201 Revision 1.2 Date: July 21, 2004.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Tarek Abdelzaher Vikram Adve CS241 Systems Programming System Calls and I/O.
File I/O open close lseek read and write – unbuffered I/O dup and dup2.
CSC 660: Advanced Operating SystemsSlide #1 CSC 660: Advanced OS Virtual Filesystem.
Dsh: A Devil Shell COMPSCI210 Recitation 14 Sep 2012 Vamsi Thummala.
CSC Java Programming, Fall, 2008 August 28, 2008, class 2 Tuesday, September 2 uses Monday’s schedule!
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
The Shell What does a shell do? - execute commands, programs - but how? For built in commands run some code to do the command For other commands find program.
Implementation of a simple shell, xssh
Implementation of a simple shell, xssh (Section 1 version)
Implementation of a simple shell, xssh
FILE LOCK #include <stdio.h> #include <stdlib.h>
IT 344: Operating Systems Module 4 Processes
UNIX FILES
Fork and Exec Unix Model
File redirection ls > out
Virtual Memory CSCI 380: Operating Systems Lecture #7 -- Review and Lab Suggestions William Killian.
IPC Prof. Ikjun Yeom TA – Hoyoun
CSCI 380: Operating Systems William Killian
IT 344: Operating Systems Winter 2008 Module 4 Processes
FILE I/O File Descriptors I/O Efficiency File Sharing
Presentation transcript:

CSC Advanced Unix Programming, Fall, 2008 Welcome back to UNIX System Programming! Monday, September 15, class 4

UNIX random access files lseek(int fd, int offset, int whence) seeks within a file, offset is location to which to go whence is one of SEEK_SET (from start), SEEK_CUR (from current), SEEK_END (from end). Do not use O_APPEND! It seeks to the end of file on appends. See ~parson/UnixSysProg/lecture4/seeklock/.

fcntl() (file control) is a catch all, like ioctl() (I/O control) int fcntl(int fildes, int cmd, /* arg */...); F_GETLK, F_SETLK, F_SETLKW manipulate file locks. Third argument to F_SETLK[W] must be a * struct flock. short l_type; /* lock operation type */ short l_whence; /* SEEK_SET, SEEK_CUR, or SEEK_END */ off_t l_start; /* starting offset from base */ off_t l_len; /* lock length; l_len == 0 means until end of file */ int l_sysid; /* system ID running process holding lock */ pid_t l_pid; /* process ID of process holding lock*/ Struct l_type field gets F_RDLCK (shared), F_WRLCK (exclusive), or F_UNLCK (unlock).

A multi-process (and eventually networked) game framework /export/home/faculty/parson/gchess GNU chess is a terminal I/O chess game gzcat gnuchess-5.07.tar.gz | tar xvf – cd gnuchess-5.07 ;./configure ; gmake cd src ; export PATH=“`pwd`:${PATH}” OR cd src ; setenv PATH =“`pwd`:${PATH}” gnuchess builds in the src/ directory.

Play terminal I/O chess and examine its process gnuchess show board, e2 e4, etc. ps -flu parson – inspect PID and PPID 0 O parson gnuchess pfiles It is using only stdin, stdout and stderr! They are all type S_IFCHR. “quit” or “exit” to get out

xboard is a GUI that runs and displays gnuchess cd /export/home/faculty/parson/gchess gzcat xboard tar.gz | tar xvf – cd xboard ;./configure ; gmake export PATH=“`pwd`:${PATH}” OR setenv PATH =“`pwd`:${PATH}” xboard builds in the xboard / directory. Invoking “xboard” requires having Hummingbird -> Exceed or another X11 display server running on your terminal.

xboard under X11 on Sun

Processes under xboard ps –flu shows three processes 0 S parson /xboard 0 S parson /bin/sh /export/home/faculty/parson 0 O parson gnuchess xboard shows stdin, stdout and stderr open All 3 are type S_IFIFO

Processes under xboard continued shows four open file descriptors fd 0, 1 and 2 are S_IFIFO fd 19: S_IFREG, O_RDONLY|O_LARGEFILE FD_CLOEXEC shows 8 open file descriptors It is good that we don’t have to analyze X11 communication protocols in order to get started! S_IFCHR, S_IFSOCK, S_IFDOOR, S_IFIFO

Assignment: Spy on GNU chess! Your initial assignment is to write an interceptor that sits between xboard and gnuchess and logs interactions while you play chess. Use your trace log plus source code and docs to understand the xboard gnuchess command and results protocol. xboard interceptor gnuchess xboard » stdin log, stdout log, stderr log for gnuchess

The bigger assignment: Sound Install ChucK on a machine with some speakers. My chess program, linked to my web page, as a ChucK directory, with a README. Open Sound Control (OSC) over UDP datagrams  a ChucK process running my sound generator  speakers But, Professor Parson, where do the OSC/UDP datagrams comes from?

A Python chess-to-music game One or more Python game GUIs  Python game server that takes commands from command line (stdin / stdout), and also accepts GUI commands from UDP datagrams. This Python program generates OSC/UDP  ChucK. The command line server, like gnuchess, is a stdin / stdout / stderr process.

Project goals Allow Python chess-to-music program to play a human against the machine (gnuchess). Support alternative, networked GUI (in Python) for gnuchess. Have some fun while learning fork, exec, file IO, sockets, networking and multithreading. Live long and prosper.

Summary Ultimately you are creating a game framework to integrate two or more running games. An ideal goal would be to allow support for different protocols using a plugin parser. The immediate goal is to intercept, redirect, etc. commands passing between xboard gnuchess, and also my Python game server Python GUI, and to translate between them.