Appendix Example Code

Size: px
Start display at page:

Download "Appendix Example Code"

Transcription

1 Appendix A Example Code Tornado Training Workshop Copyright A-1 ynchronization essage Queues: Data Collection essage Queues: Client - Server xception Handling elect ( ) DP CP emo code

2 Synchronization Solution 1 #include vxworks.h 2 #include semlib.h 3 #include intlib.h 4 5 LOCAL SEM_ID mysemid; 6 7 void myinit( ) 8 { 9 /* Initialize software/hardware for device */ mysemid = sembcreate (SEM_Q_FIFO, SEM_EMPTY); 12 intconnect (MY_INT_VEC, myisr, 0); 13 } void mygetdata( ) 16 { 17 /* Tweak device registers to start I/O */ /* Wait for interrupt indicating data is ready */ 20 semtake (mysemid, WAIT_FOREVER); 21 /* use the data */ } LOCAL void myisr( ) 26 { 27 /* Interrupt generated from external device */ semgive (mysemid); 30 } 31 Synchronization A-2

3 Message Queues: Data Collection 1 #include vxworks.h 2 #include tasklib.h 3 #include msgqlib.h 4 #include mylib.h 5 6 LOCAL MSG_Q_ID mymsgqid; 7 8 STATUS myinit (void) 9 { 10 /* Software/hardware initialization done here */ mymsgqid = msgqcreate (MAX_MSGS, MAX_SIZE, 13 MSG_Q_PRIORITY); 14 if (mymsgqid == NULL) 15 return (ERROR); 16 if (taskspawn (..., mypollingcode,...) == ERROR) 17 { 18 msgqdelete (mymsgqid); 19 return (ERROR); 20 } 21 return (OK); 22 } LOCAL void mypollingcode (void) 25 { 26 for (;;) 27 { 28 taskdelay (DELAY_PERIOD); 29 /* Read data from device & */ 30 /* place into message queue*/ if (msgqsend (mymsgqid,...) == ERROR) 33 handletheerror( ); 34 } 35 } int mygetdata (char * pbuf) 38 { 39 return (msgqreceive (mymsgqid, pbuf,...)); 40 } Message Queues: Data Collection A-3

4 Message Queues: Client - Server 1 #include vxworks.h 2 #include tasklib.h 3 #include msgqlib.h 4 #include mylib.h 5 6 LOCAL MSG_Q_ID mymsgqid; 7 8 STATUS myinit (void) 9 { 10 /* Server initialization done here */ mymsgqid = msgqcreate (MAX_MSGS, MSG_SIZE, 13 MSG_Q_PRIORITY); 14 if (mymsgqid == NULL) 15 return (ERROR); 16 if (taskspawn (..., myservercode,...) == ERROR) 17 { 18 msgqdelete (mymsgqid); 19 return (ERROR); 20 } 21 return (OK); 22 } LOCAL void myservercode (void) 25 { 26 for (;;) 27 { 28 /* Wait to receive next request */ 29 if (msgqreceive (mymsgqid, pbuf,...) 30 == ERROR) 31 handletheerror(); 32 /* Service the request */ } 35 } STATUS mysendrequest (MY_REQUEST * prequest) 38 { 39 return (msgqsend (mymsgqid, prequest,...)); 40 } Message Queues: Client - Server A-4

5 Exception Handling 1 #include vxworks.h 2 #include tasklib.h 3 #include setjmp.h 4 #include signal.h 5 #include foolib.h 6 7 jmp_buf location; /* Destination for jump */ 8 9 STATUS fooinit (void) 10 { 11 footid = taskspawn ( tfoopoll, FOO_PRIORITY, 12 FOO_OPTIONS, FOO_STACK_SIZE, 13 (FUNCPTR) foopoll, 0, 0, 0, , 0, 0, 0, 0, 0); 15 if (footid == ERROR) 16 return ERROR; 17 return OK; 18 } LOCAL void foopoll (void) 21 { signal (SIGBUS, foohandler); 24 signal (SIGSEGV, foohandler); FOREVER 27 { 28 if (setjmp (location)!= 0) 29 foologdeverror ( ); 30 fooaccessdev ( ); 31 foologdata ( ); 32 } 33 } LOCAL void foohandler (int signum) 36 { 37 fooresetdev ( ); 38 longjmp (location, 100); 39 } setjmp( ) s return value Exception Handling A-5

6 select( ) 1 #include vxworks.h 2 #include fiolib.h 3 #include selectlib.h 4 #include foolib.h 5 6 LOCAL struct fd_set readfds, tmpfds; 7 LOCAL int fds[num_fds]; 8 LOCAL int width = 0; 9 char channelname[20]; /************************************************ 12 * fooreadinit - Attempt to open channels /dev/0 13 * through /dev/n, N == NUM_FDS-1. For each 14 * channel opened, set the bit of the corresponding 15 * file descriptor in readfds. 16 * RETURNS: The number of channels opened. 17 */ int fooreadinit(void) 20 { 21 int i; /* channel number */ 22 int j; /* index into fds */ 23 /* Initialize read fd_set structure */ FD_ZERO (&readfds); 26 for (i=0, j=0; i < NUM_FDS; i++) 27 { 28 int fd; sprintf (channelname, %s%d, /dev/, i); 31 if ((fd = open(channelname, O_RDWR, 0))>=0) 32 { 33 fds[j++] = fd; 34 FD_SET (fd, &readfds); 35 width = max (fd, width); 36 } 37 } 38 width++; 39 return j; /* Number successfully opened */ 40 } select( ) A-6

7 select( ) Example, continued. 41 /************************************************* 42 * fooread - Service requests arriving over the 43 * nfds file descriptors in the fds[] array. 44 */ void fooread 47 ( 48 int nfds /* # file descriptors in fds[] */ 49 ) 50 { 51 int i; if (nfds <= 0) 54 exit (errno = S_fooLib_BAD_NFDS); /* Call select and wait for read activity */ 57 FOREVER 58 { 59 tmpfds = readfds; 60 if (select (width, &tmpfds, NULL,NULL,NULL) 61 == ERROR) 62 { 63 for (i=0; i < nfds; i++) 64 close (fds[i]); 65 exit (ERROR); 66 } 67 else 68 for (i=0; i < nfds; i++) 69 if (FD_ISSET (fds[i], &tmpfds)) 70 foodorequest (fds[i]); 71 } 72 } /************************************************ 75 * foodorequest - Read the null-terminated 76 * request,and send back the string 77 * You ve got to be kidding!\n 78 */ select( ) A-7

8 Demo Code - WindView Demo demotransfer.c 79 /* demotransfer.c - pass blocks between two tasks */ /* sloppy test program */ #include vxworks.h 84 #include msgqlib.h 85 #include stdlib.h 86 #include stdio.h 87 #include tasklib.h 88 #include wvutillib.h /* globals */ int senderdelayticks = 1; 94 int receiverdelayticks = 1; int sendtask = ERROR; 97 int receivetask = ERROR; int taskoptions = 0; 100 int taskstack = 10000; int senderpriority = 80; 103 int receiverpriority = 90; MSG_Q_ID transferq = NULL; int blk_size = 4096; 108 int QBlocks = 16; 109 int QOptions = MSG_Q_FIFO; BOOL transferstarted = FALSE; /* forward declarations */ void send1 (MSG_Q_ID mq); 116 void receive1 (MSG_Q_ID mq); void datawrite (char * pblock, size_t nbytes); select( ) A-8

9 119 void dataprocess (char * pblock, size_t nbytes); STATUS transferstart (void) 122 { 123 if (transferstarted) 124 return ERROR; transferq = msgqcreate (QBlocks, sizeof (char *), 127 QOptions); receivetask = 130 taskspawn ( trecv1, receiverpriority, 131 taskoptions, taskstack, 132 (FUNCPTR) receive1, (int) transferq, 133 0,0,0,0,0,0,0,0,0); sendtask = taskspawn ( tsend1, senderpriority, 136 taskoptions, taskstack, 137 (FUNCPTR) send1, (int) transferq, 138 0,0,0,0,0,0,0,0,0); transferstarted = TRUE; 141 return OK; 142 } STATUS transferstop (void) 145 { 146 if (!transferstarted) 147 return ERROR; msgqdelete (transferq); transferstarted = FALSE; 152 return OK; 153 } void send1 156 ( 157 MSG_Q_ID mq 158 ) 159 { 160 char * pch; FOREVER 163 { select( ) A-9

10 164 if ( (pch = (char *) malloc (blk_size)) 165 == NULL) 166 { 167 printf ( Out of memory in task %s.\n, 168 taskname(0)); 169 return; 170 } datawrite (pch, blk_size); if (msgqsend (mq, (char *)&pch, sizeof (pch), 175 WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR) 176 { 177 printf ( msgqsend failed.\n ); 178 free (pch); 179 return; 180 } taskdelay (senderdelayticks); 183 } 184 } VOID receive1 187 ( 188 MSG_Q_ID mq 189 ) 190 { 191 char * pch; FOREVER 194 { 195 if (msgqreceive (mq, (char *) &pch, 196 sizeof (pch), WAIT_FOREVER) 197!= sizeof (pch)) 198 { 199 printf ( msgqreceive failed.\n ); 200 return; 201 } dataprocess (pch, blk_size); 204 free (pch); 205 } 206 } select( ) A-10

11 209 void datawrite 210 ( 211 char * pblock, 212 size_t nbytes 213 ) 214 { int * pi = (int *) pblock; 217 size_t nints = nbytes / 4; 218 int x = 0; 219 WV_EVT (1); 220 while (pi - (int *) pblock < nints) 221 *pi++ = x++; 222 WV_EVT (2); 223 } void dataprocess 226 ( 227 char* pblock, 228 size_t nbytes 229 ) 230 { 231 size_t nints = nbytes / 4; 232 int * pbeg = (int *) pblock; 233 int * pend = pbeg + (nints - 1); 234 int x; 235 WV_EVT (3); 236 while (pend > pbeg) 237 { 238 x = *pend; 239 *pend-- = *pbeg; 240 *pbeg++ = x; 241 } 242 WV_EVT (4); 243 } select( ) A-11

12 Demo Code - WindView Demo 1 wvutillib./* wvutillib.h - WindView utility macros */ 2 3 /* Copyright 1998, Inc. */ 4 5 /* 6 modification history a,03nov98,dlk written. 9 */ #ifndef INCwvUtilLibh 12 #define INCwvUtilLibh #include vxworks.h 15 #include wvlib.h 16 #include private/wvbufferp.h 17 #include private/wvuploadpathp.h 18 #include private/wvsockuploadpathlibp.h 19 #include private/eventp.h #ifdef cplusplus 22 extern C { 23 #endif /* cplusplus */ /* defines */ #ifdef WV_INSTR /************************************************** 33 * The default upload path depends on the components 34 * that are included : 35 * 36 * if (upload file is included) 37 * default upload path = file 38 * else if (TSFS socket is included) 39 * default upload path = TSFS socket 40 * else 41 * default upload path = socket 42 * select( ) A-12

13 43 * That is, the default upload path will be the LAST 44 * of the following which is included in the VxWorks 45 * configuration: 46 * 47 * TCP/IP socket upload path 48 * TSFS socket upload path 49 * File upload path 50 * 51 * (See usrwindviewinit() in prjconfig.c) If none of 52 * these are included, there is a configuration 53 * error. 54 * 55 * You can use the WV_START macro to start event 56 * log upload from your application. You can use the 57 * macro as follows, assuming that the default 58 * path is socket and that you want to upload to the 59 * host from which the target boots, and evtrecv or a 60 * graph is listening on the default port 6164: 61 * 62 * WV_START(WV_CLASS_3, sysboothost, 6164 ); 63 */ #define WV_START(evtClass, path, arg)\ 66 wvon(evtclass, path, arg, 0) #define WV_STOP\ 69 do {\ 70 if (wvevtbufferget())\ 71 wvoff();\ 72 } while (FALSE) #define WV_EVT(id) \ 75 wvevent ((id), (char *)NULL, 0) #define WV_EVT_STRING(id, str) \ 78 wvevent ((id), (char *)(str), strlen(str) + 1) #define WV_EVT_OBJ(id, obj) \ 81 wvevent ((id), (char *)&(obj), sizeof (obj)) #define WV_EVT_ARRAY(id, array) \ 84 wvevent ((id), (char *)(array), sizeof (array)) #define WV_INST_SEM(semId) \ 87 wvobjinst (OBJ_SEM, (semid), INSTRUMENT_ON) select( ) A-13

14 88 89 #define WV_INST_MSGQ(msgQId) \ 90 wvobjinst (OBJ_MSG, (msgqid), INSTRUMENT_ON) #define WV_INST_WDOG(wdogId) \ 93 wvobjinst (OBJ_WD, (wdogid), INSTRUMENT_ON) #define WV_INST_TASK(taskId) \ 96 wvobjinst (OBJ_TASK, (void *) (taskid), \ 97 INSTRUMENT_ON) #define WV_OBJ_INST_ON \ 100 wvobjinstmodeset (INSTRUMENT_ON) #define WV_OBJ_INST_OFF \ 103 wvobjinstmodeset (INSTRUMENT_OFF) #else /* WV_INSTR not defined */ #define WV_EVT(id) (void) OK 108 #define WV_EVT_STRING(id, str) (void) OK 109 #define WV_EVT_OBJ(id, obj) (void) OK 110 #define WV_EVT_ARRAY(id, array) (void) OK 111 #define WV_INST_SEM(semId) (void) OK 112 #define WV_INST_MSGQ(msgQId) (void) OK 113 #define WV_INST_WDOG(sdogId) (void) OK 114 #define WV_INST_TASK(taskId) (void) OK 115 #define WV_OBJ_INST_ON (void) OK 116 #define WV_OBJ_INST_OFF (void) OK 117 #define WV_START(evtClass, path, arg) (void) OK 118 #define WV_STOP #endif /* WV_INSTR */ 121 /* typedefs */ /* function declarations */ #ifdef cplusplus 126 } 127 #endif /* cplusplus */ #endif /* INCwvUtilLibh */ select( ) A-14

6/20/2018. Lecture 5: Real Time Messages

6/20/2018. Lecture 5: Real Time Messages Lecture 5: Real Time Messages 1 Quiz (10 min) Groups Presentations (45) Lecture: RT Messages (45) Lab exercise Messages and Pipes (60) Exam 1: Discussion 2 1 3 The message-driven approach is used both

More information

Semaphores. Chapter. verview inary Semaphores for Task Synchronization utex Semaphores to Solve Mutual Exclusion Problems

Semaphores. Chapter. verview inary Semaphores for Task Synchronization utex Semaphores to Solve Mutual Exclusion Problems Chapter 7 Semaphores Tornado Training Workshop Copyright 7-1 verview inary Semaphores for Task Synchronization utex Semaphores to Solve Mutual Exclusion Problems 7.1 Overview Semaphores Binary Semaphores

More information

Lab Manual for VxWorks

Lab Manual for VxWorks Lab Manual for VxWorks Session 1: Introduction to Tornado tool 1] A program to display hello world on the console window. Also find the size of the structure with a char an as the data member of the structure.

More information

10. I/O System Library

10. I/O System Library 10. I/O System Library Header File #include // Found in C:\Nburn\include General File Descriptor Functions close --- Close open file descriptors read --- Read data from a file descriptor ReadWithTimeout

More information

Exceptions, Interrupts, and Timers

Exceptions, Interrupts, and Timers Chapter 10 Exceptions, Interrupts, and Timers Tornado Training Workshop Copyright 10-1 xception Handling and Signals nterrupt Service Routines ystem Clock, Auxiliary Clock, Watchdog Timers Exceptions,

More information

Laboratório de Mecatrônica EESC/USP SEM VxWorks/Workbench. Jean M.S.C. Yabarrena 30/04/10

Laboratório de Mecatrônica EESC/USP SEM VxWorks/Workbench. Jean M.S.C. Yabarrena 30/04/10 Laboratório de Mecatrônica EESC/USP SEM 0544 VxWorks/Workbench Jean M.S.C. Yabarrena 30/04/10 Motivação Como interagir com o VxWorks e como utilizar seus recursos Objetivos Utilizar uma utilidade que utiliza

More information

Interrupt Timer I/O operations

Interrupt Timer I/O operations Interrupt vector table Interrupt service routine(isr) Usr ISR Interrupt Timer I/O operations Vector number hardware handler Handler: Save registers Call routine Restore registers RET myisr() Interrupts

More information

Computer Systems Assignment 2: Fork and Threads Package

Computer Systems Assignment 2: Fork and Threads Package Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes

More information

Experiment #3 Semaphores

Experiment #3 Semaphores Experiment #3 Semaphores Introduction Semaphores permit multitasking applications to coordinate their activities. The most obvious way for tasks to communicate is via various shared data structures. Because

More information

Advcan QNX Driver User Manual V1.02

Advcan QNX Driver User Manual V1.02 Advcan QNX Driver User Manual V1.02 Contents 1. Introduction...1 1.1. System Requirement...1 1.2. Driver configuration...1 2. AdvCan Data Structures...2 2.1. Canmsg_t Struct Reference...2 2.2. CanStatusPar

More information

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland t Your task Write a simple file server Client has to be implemented in Java Server has to be implemented

More information

FYS4220 / RT-lab no SIGNALS

FYS4220 / RT-lab no SIGNALS FYS4220 / 9220 12 Oct 2011 /TBS RT-lab no 2-2011 SIGNALS 1 The VxWorks signal IPC facility VxWorks provides a software signal facility. Signals asynchronously alter the control flow of a task or process.

More information

1. We have a code sequence that is potentially executed twice.

1. We have a code sequence that is potentially executed twice. Long Jump Long Jump Local Jumps In the following example: 1. We have a code sequence that is potentially executed twice. 2. A flag is used to determine whether the sequence is being executed the first

More information

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo

CONCURRENCY MODEL. UNIX Programming 2014 Fall by Euiseong Seo CONCURRENCY MODEL UNIX Programming 2014 Fall by Euiseong Seo Echo Server Revisited int main (int argc, char *argv[]) {... listenfd = socket(af_inet, SOCK_STREAM, 0); bzero((char *)&saddr, sizeof(saddr));

More information

Experiment #7 Priority Inversion

Experiment #7 Priority Inversion Experiment #7 Priority Inversion Introduction Priority inversion occurs when a higher-priority task is forced to wait an indefinite period for the completion of a lower priority task. For example, priohigh,

More information

Workshop on Inter Process Communication Solutions

Workshop on Inter Process Communication Solutions Solutions 1 Background Threads can share information with each other quite easily (if they belong to the same process), since they share the same memory space. But processes have totally isolated memory

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song CSCE 313 Introduction to Computer Systems Instructor: Dezhen Song UNIX I/O Files and File Representation Basic operations: Reading / Writing Caching: File Open / Close Multiplexing: Select / Poll File

More information

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line

Operating Systems. Lecture 06. System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line Operating Systems Lecture 06 System Calls (Exec, Open, Read, Write) Inter-process Communication in Unix/Linux (PIPE), Use of PIPE on command line March 04, 2013 exec() Typically the exec system call is

More information

CS118 Discussion Week 2. Taqi

CS118 Discussion Week 2. Taqi CS118 Discussion Week 2 Taqi Outline Any Questions for Course Project 1? Socket Programming: Non-blocking mode Lecture Review: Application Layer Much of the other related stuff we will only discuss during

More information

CSci 4061 Introduction to Operating Systems. Programs in C/Unix

CSci 4061 Introduction to Operating Systems. Programs in C/Unix CSci 4061 Introduction to Operating Systems Programs in C/Unix Today Basic C programming Follow on to recitation Structure of a C program A C program consists of a collection of C functions, structs, arrays,

More information

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT

C Review. MaxMSP Developers Workshop Summer 2009 CNMAT C Review MaxMSP Developers Workshop Summer 2009 CNMAT C Syntax Program control (loops, branches): Function calls Math: +, -, *, /, ++, -- Variables, types, structures, assignment Pointers and memory (***

More information

Intermediate Programming, Spring 2017*

Intermediate Programming, Spring 2017* 600.120 Intermediate Programming, Spring 2017* Misha Kazhdan *Much of the code in these examples is not commented because it would otherwise not fit on the slides. This is bad coding practice in general

More information

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0;

#include <stdio.h> int main() { char s[] = Hsjodi, *p; for (p = s + 5; p >= s; p--) --*p; puts(s); return 0; 1. Short answer questions: (a) Compare the typical contents of a module s header file to the contents of a module s implementation file. Which of these files defines the interface between a module and

More information

ECE 435 Network Engineering Lecture 2

ECE 435 Network Engineering Lecture 2 ECE 435 Network Engineering Lecture 2 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 31 August 2017 Announcements Homework 1 will be posted. Will be on website, will announce

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Sciences and Engineering INTERNAL ASSESSMENT TEST 2 Solutions 1. Explain the working of the waitpid() API with the help of a program. The program needs to take 2 command line arguments: the first argument should be used as the

More information

Network Games Part II. Architecture of Network Game

Network Games Part II. Architecture of Network Game Network Games Part II Doron Nussbaum Network Games Part II COMP 5900 1 Architecture of Network Game Client Server Peer to Peer Player 1 Player 2 Player 1 Player 2 Server Player 5 Player 3 Player 5 Player

More information

AppNote-124 Adding "Flow Control" to an END or NPT type network driver

AppNote-124 Adding Flow Control to an END or NPT type network driver Adding "Flow Control" to an END or NPT type network driver Adding "Flow Control" to a non-wind River supplied END or NPT network driver to prevent unrecoverable loss of network communication in a heavy

More information

COMP/ELEC 429/556 Introduction to Computer Networks

COMP/ELEC 429/556 Introduction to Computer Networks COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene Ng, Ion Stoica, Hui Zhang 1 How to Programmatically

More information

CSE 333 Midterm Exam Sample Solution 7/28/14

CSE 333 Midterm Exam Sample Solution 7/28/14 Question 1. (20 points) C programming. For this question implement a C function contains that returns 1 (true) if a given C string appears as a substring of another C string starting at a given position.

More information

CSC209H Lecture 10. Dan Zingaro. March 18, 2015

CSC209H Lecture 10. Dan Zingaro. March 18, 2015 CSC209H Lecture 10 Dan Zingaro March 18, 2015 Creating a Client To create a client that can connect to a server, call the following, in order: socket: create a communication endpoint This is the same as

More information

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function

NETWORK AND SYSTEM PROGRAMMING. I/O Multiplexing: select and poll function NETWORK AND SYSTEM PROGRAMMING LAB 15 I/O Multiplexing: select and poll function 15.1 objectives What is a Concurrent server Use of Select System call Use of Poll System call 15.2 What is concurrent server?

More information

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes

COSC Operating Systems Design, Fall Lecture Note: Unnamed Pipe and Shared Memory. Unnamed Pipes COSC4740-01 Operating Systems Design, Fall 2001 Lecture Note: Unnamed Pipe and Shared Memory Unnamed Pipes Pipes are a form of Inter-Process Communication (IPC) implemented on Unix and Linux variants.

More information

Any of the descriptors in the set {1, 4} have an exception condition pending

Any of the descriptors in the set {1, 4} have an exception condition pending Page 1 of 6 6.3 select Function This function allows the process to instruct the kernel to wait for any one of multiple events to occur and to wake up the process only when one or more of these events

More information

We start by looking at what s known as event-based programming: we write code that responds to events coming from a number of sources.

We start by looking at what s known as event-based programming: we write code that responds to events coming from a number of sources. We start by looking at what s known as event-based programming: we write code that responds to events coming from a number of sources. As a simple example, before we use the approach in a networking example,

More information

TPMC821-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. INTERBUS Master G4 PMC. Version 1.4. Issue 1.

TPMC821-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. INTERBUS Master G4 PMC. Version 1.4. Issue 1. The Embedded I/O Company TPMC821-SW-42 VxWorks Device Driver INTERBUS Master G4 PMC Version 1.4 User Manual Issue 1.2 January 2004 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 25469 Halstenbek / Germany Phone:

More information

A Crash Course in C. Steven Reeves

A Crash Course in C. Steven Reeves A Crash Course in C Steven Reeves This class will rely heavily on C and C++. As a result this section will help students who are not familiar with C or who need a refresher. By the end of this section

More information

an infinite loop Processes and Exceptions doing nothing on a busy system timing nothing

an infinite loop Processes and Exceptions doing nothing on a busy system timing nothing an infinite loop Processes and Exceptions int main(void) { while (1) { /* waste CPU time */ If I run this on a lab machine, can you still use it? even if the machine only has one core? 1 2 timing nothing

More information

ISA 563: Fundamentals of Systems Programming

ISA 563: Fundamentals of Systems Programming ISA 563: Fundamentals of Systems Programming Advanced IO April 9, 2012 Non-blocking IO Data processing can be much faster than data access Waiting for IO to finish can be time consuming, and may not even

More information

CSC209H Lecture 9. Dan Zingaro. March 11, 2015

CSC209H Lecture 9. Dan Zingaro. March 11, 2015 CSC209H Lecture 9 Dan Zingaro March 11, 2015 Socket Programming (Kerrisk Ch 56, 57, 59) Pipes and signals are only useful for processes communicating on the same machine Sockets are a general interprocess

More information

I/O Models. Kartik Gopalan

I/O Models. Kartik Gopalan I/O Models Kartik Gopalan Types of Concurrency True Concurrency (multiple processes or threads) Multi-processor machines Child processes/threads execute in parallel. Multi-process (forking) servers If

More information

Socket programming in C

Socket programming in C Socket programming in C Sven Gestegård Robertz September 2017 Abstract A socket is an endpoint of a communication channel or connection, and can be either local or over the network.

More information

File Descriptors and Piping

File Descriptors and Piping File Descriptors and Piping CSC209: Software Tools and Systems Programming Furkan Alaca & Paul Vrbik University of Toronto Mississauga https://mcs.utm.utoronto.ca/~209/ Week 8 Today s topics File Descriptors

More information

Input and Output System Calls

Input and Output System Calls Chapter 2 Input and Output System Calls Internal UNIX System Calls & Libraries Using C --- 1011 OBJECTIVES Upon completion of this unit, you will be able to: Describe the characteristics of a file Open

More information

Advanced Pointer & Data Storage

Advanced Pointer & Data Storage 18, 19: storage classes 14: Preprocessor & Polymorphism in C) 15 : command line building 26 : stdarg Advanced Pointer & Data Storage (for ch. 14, 15 18, 19, 26) Contents Preprocessor & Polymorphism in

More information

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community

CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community CSCI-243 Exam 1 Review February 22, 2015 Presented by the RIT Computer Science Community http://csc.cs.rit.edu History and Evolution of Programming Languages 1. Explain the relationship between machine

More information

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems

Deep C. Multifile projects Getting it running Data types Typecasting Memory management Pointers. CS-343 Operating Systems Deep C Multifile projects Getting it running Data types Typecasting Memory management Pointers Fabián E. Bustamante, Fall 2004 Multifile Projects Give your project a structure Modularized design Reuse

More information

ECE 435 Network Engineering Lecture 2

ECE 435 Network Engineering Lecture 2 ECE 435 Network Engineering Lecture 2 Vince Weaver http://web.eece.maine.edu/~vweaver vincent.weaver@maine.edu 6 September 2018 Announcements Homework 1 will be posted. Will be on website, will announce

More information

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Dynamic Memory Management. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Dynamic Memory Management Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island 1 Dynamic Memory Allocation Dynamic memory allocation is used to

More information

Introduction to N1031. Components of N1031. Guiding Principles. Walk through, issues, and rationale

Introduction to N1031. Components of N1031. Guiding Principles. Walk through, issues, and rationale Introduction to N1031 Walk through, issues, and rationale Components of N1031 New functions that protect against buffer overflow and always produce null terminated strings New reentrant versions of old

More information

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto

Ricardo Rocha. Department of Computer Science Faculty of Sciences University of Porto Ricardo Rocha Department of Computer Science Faculty of Sciences University of Porto Adapted from the slides Revisões sobre Programação em C, Sérgio Crisóstomo Compilation #include int main()

More information

Real Time College. These are the methods, variables and definitions that you may use throughout home and class exercises :

Real Time College. These are the methods, variables and definitions that you may use throughout home and class exercises : These are the methods, variables and definitions that you may use throughout home and class exercises : Definitions: #define INIFINITE_TIMEOUT 0xFFFFFFFF #define POLICY_FIFO 0x1 #define POLICY_PRIORITY

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files ... and systems programming C basic syntax functions arrays structs

More information

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs.

CSC209: Software tools. Unix files and directories permissions utilities/commands Shell programming quoting wild cards files. Compiler vs. CSC209 Review CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files... and systems programming C basic syntax functions arrays structs

More information

UNIX System Programming

UNIX System Programming File I/O 경희대학교컴퓨터공학과 조진성 UNIX System Programming File in UNIX n Unified interface for all I/Os in UNIX ü Regular(normal) files in file system ü Special files for devices terminal, keyboard, mouse, tape,

More information

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report

CODE TIME TECHNOLOGIES. Abassi RTOS MISRA-C:2004. Compliance Report CODE TIME TECHNOLOGIES Abassi RTOS MISRA-C:2004 Compliance Report Copyright Information This document is copyright Code Time Technologies Inc. 2012. All rights reserved. No part of this document may be

More information

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes CSci 4061 Introduction to Operating Systems IPC: Basics, Pipes Communication IPC in Unix Pipes: most basic form of IPC in Unix process-process ps u jon grep tcsh // what happens? Pipe has a read-end (receive)

More information

CYSE 411/AIT681 Secure Software Engineering Topic #8. Secure Coding: Pointer Subterfuge

CYSE 411/AIT681 Secure Software Engineering Topic #8. Secure Coding: Pointer Subterfuge CYSE 411/AIT681 Secure Software Engineering Topic #8. Secure Coding: Pointer Subterfuge Instructor: Dr. Kun Sun This lecture: [Seacord]: Chapter 3 Readings 2 Outline Secure Coding Topics String management

More information

RTOS VxWorks 6.x. Ing. Michal Sojka, Ing. Zdeněk Šebek

RTOS VxWorks 6.x. Ing. Michal Sojka, Ing. Zdeněk Šebek RTOS VxWorks 6.x Ing. Michal Sojka, Ing. Zdeněk Šebek Czech Technical University in Prague, Faculty of Electrical Engineering, Department of Control Engineering Topics VxWorks 6.x kernel components, properties

More information

Shared Memory Memory mapped files

Shared Memory Memory mapped files Shared Memory Memory mapped files 1 Shared Memory Introduction Creating a Shared Memory Segment Shared Memory Control Shared Memory Operations Using a File as Shared Memory 2 Introduction Shared memory

More information

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes CSci 4061 Introduction to Operating Systems IPC: Basics, Pipes Communication IPC in Unix Pipes: most basic form of IPC in Unix process-process ps u jon grep tcsh // what happens? Pipe has a read-end (receive)

More information

Secure Coding Topics. Readings. CYSE 411/AIT681 Secure Software Engineering. Pointer Subterfuge. Outline. Data Locations (cont d) Data Locations

Secure Coding Topics. Readings. CYSE 411/AIT681 Secure Software Engineering. Pointer Subterfuge. Outline. Data Locations (cont d) Data Locations This lecture: [Seacord]: Chapter 3 Readings CYSE 411/AIT681 Secure Software Engineering Topic #8. Secure Coding: Pointer Subterfuge Instructor: Dr. Kun Sun 2 Outline Secure Coding Topics String management

More information

Secure Coding Topics. CYSE 411/AIT681 Secure Software Engineering. Readings. Outline. This lecture: Topic #8. Secure Coding: Pointer Subterfuge

Secure Coding Topics. CYSE 411/AIT681 Secure Software Engineering. Readings. Outline. This lecture: Topic #8. Secure Coding: Pointer Subterfuge CYSE 411/AIT681 Secure Software Engineering Topic #8. Secure Coding: Pointer Subterfuge Instructor: Dr. Kun Sun This lecture: [Seacord]: Chapter 3 Readings 2 Outline Secure Coding Topics String management

More information

Computational Methods of Scientific Programming Fall 2007

Computational Methods of Scientific Programming Fall 2007 MIT OpenCourseWare http://ocw.mit.edu 12.010 Computational Methods of Scientific Programming Fall 2007 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms.

More information

TPMC500-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. 32 Channel 12 Bit ADC. Version 2.0.x. Issue 2.0.

TPMC500-SW-42. VxWorks Device Driver. User Manual. The Embedded I/O Company. 32 Channel 12 Bit ADC. Version 2.0.x. Issue 2.0. The Embedded I/O Company TPMC500-SW-42 VxWorks Device Driver 32 Channel 12 Bit ADC Version 2.0.x User Manual Issue 2.0.0 October 2004 TEWS TECHNOLOGIES GmbH Am Bahnhof 7 e-mail: info@tews.com 25469 Halstenbek

More information

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco

CS 326 Operating Systems C Programming. Greg Benson Department of Computer Science University of San Francisco CS 326 Operating Systems C Programming Greg Benson Department of Computer Science University of San Francisco Why C? Fast (good optimizing compilers) Not too high-level (Java, Python, Lisp) Not too low-level

More information

33. Event-based Concurrency

33. Event-based Concurrency 33. Event-based Concurrency Oerating System: Three Easy Pieces AOS@UC 1 Event-based Concurrency A different style of concurrent rogramming without threads w Used in GUI-based alications, some tyes of internet

More information

ECE 650 Systems Programming & Engineering. Spring 2018

ECE 650 Systems Programming & Engineering. Spring 2018 ECE 650 Systems Programming & Engineering Spring 2018 Inter-process Communication (IPC) Tyler Bletsch Duke University Slides are adapted from Brian Rogers (Duke) Recall Process vs. Thread A process is

More information

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links

Linked-List Basic Examples. A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Linked-List Basic Examples A linked-list is Linear collection of self-referential class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Subsequent

More information

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Data Types Basic Types Enumerated types The type void Derived types

More information

ECE264 Fall 2013 Exam 3, November 20, 2013

ECE264 Fall 2013 Exam 3, November 20, 2013 ECE264 Fall 2013 Exam 3, November 20, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing it.

More information

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science

NETWORK PROGRAMMING. Instructor: Junaid Tariq, Lecturer, Department of Computer Science NETWORK PROGRAMMING CSC- 341 25 Instructor: Junaid Tariq, Lecturer, Department of Computer Science 26 9 Lecture Sockets as means for inter-process communication (IPC) application layer Client Process Socket

More information

CSE 333 Midterm Exam 2/12/16. Name UW ID#

CSE 333 Midterm Exam 2/12/16. Name UW ID# Name UW ID# There are 6 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed book, closed notes,

More information

Processes. Processes (cont d)

Processes. Processes (cont d) Processes UNIX process creation image-file arg1 arg2 Shell command line example ls -l Equivalent to /bin/ls -l Why? How do you find out where the image file is? Background processes ls -l & Execute a process

More information

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations

Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations Today: VM wrap-up Select (if time) Course wrap-up Final Evaluations Program structure int A[1024][1024] ; Each row is stored in one page Ignore code page in this example One frame allocated Program 1 for

More information

nbtcpfrm: Non Blocking TCP/IP Network Control Program CML

nbtcpfrm: Non Blocking TCP/IP Network Control Program CML nbtcpfrm: Non Blocking TCP/IP Network Control Program CML00053-01 Code Magus Limited (England reg. no. 4024745) Number 6, 69 Woodstock Road Oxford, OX2 6EY, United Kingdom www.codemagus.com Copyright c

More information

Kurt Schmidt. October 30, 2018

Kurt Schmidt. October 30, 2018 to Structs Dept. of Computer Science, Drexel University October 30, 2018 Array Objectives to Structs Intended audience: Student who has working knowledge of Python To gain some experience with a statically-typed

More information

Dynamic memory allocation

Dynamic memory allocation Dynamic memory allocation outline Memory allocation functions Array allocation Matrix allocation Examples Memory allocation functions (#include ) malloc() Allocates a specified number of bytes

More information

82V391x / 8V893xx WAN PLL Device Families Device Driver User s Guide

82V391x / 8V893xx WAN PLL Device Families Device Driver User s Guide 82V391x / 8V893xx WAN PLL Device Families Device Driver Version 1.2 April 29, 2014 Table of Contents 1. Introduction... 1 2. Software Architecture... 2 2.1. Overview... 2 2.2. Hardware Abstraction Layer

More information

The output will be: marks all or nothing. 1 #include <stdio.h> 2 main() { 3 int i; int j; 4 int *p; int *q; 6 p = &i; 7 q = &j; 8 i = 1;

The output will be: marks all or nothing. 1 #include <stdio.h> 2 main() { 3 int i; int j; 4 int *p; int *q; 6 p = &i; 7 q = &j; 8 i = 1; p. 2 of 9 Q1. [5 marks] The following program compiles and runs with no problems. Indicate what the output of the program is going to be (no explanation necessary). 1 #include 2 main() { 3 int

More information

Redesde Computadores(RCOMP)

Redesde Computadores(RCOMP) Redesde Computadores(RCOMP) Theoretical-Practical (TP) Lesson 07 2016/2017 Berkeley sockets API, C and Java. Basic functions/methods for TCP applications. TCP client and server. Asynchronous reception.

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables.

Actually, C provides another type of variable which allows us to do just that. These are called dynamic variables. When a program is run, memory space is immediately reserved for the variables defined in the program. This memory space is kept by the variables until the program terminates. These variables are called

More information

CSC209 Review. Yeah! We made it!

CSC209 Review. Yeah! We made it! CSC209 Review Yeah! We made it! 1 CSC209: Software tools Unix files and directories permissions utilities/commands Shell programming quoting wild cards files 2 ... and C programming... C basic syntax functions

More information

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C

Processes often need to communicate. CSCB09: Software Tools and Systems Programming. Solution: Pipes. Recall: I/O mechanisms in C 2017-03-06 Processes often need to communicate CSCB09: Software Tools and Systems Programming E.g. consider a shell pipeline: ps wc l ps needs to send its output to wc E.g. the different worker processes

More information

Don Libes. National Institute of Standards and Technology Gaithersburg, MD ABSTRACT

Don Libes. National Institute of Standards and Technology Gaithersburg, MD ABSTRACT Packet-oriented Communication Using a Stream Protocol or Making TCP/IP on Berkeley UNIX a little more pleasant to use Don Libes National Institute of Standards and Technology Gaithersburg, MD 20899 ABSTRACT

More information

Writing Custom SCSI Routines

Writing Custom SCSI Routines Chapter 7 Writing Custom SCSI Routines Tornado Device Driver Workshop Copyright 7-1 Overview of SCSI. Using SCSI devices in a VxWorks Environment. Configuring VxWorks for your SCSI device. Putting Device

More information

#ifndef DOUBLE_LIST /* this string SHOULD NOT previously exist */ #define DOUBLE_LIST

#ifndef DOUBLE_LIST /* this string SHOULD NOT previously exist */ #define DOUBLE_LIST /* This is a personal header file. Call it double_list.h * Its name should be reflected into the macro definition (#define). * For instance, here I should say something like: * #define DOUBLE_LIST #ifndef

More information

Section 3: File I/O, JSON, Generics. Meghan Cowan

Section 3: File I/O, JSON, Generics. Meghan Cowan Section 3: File I/O, JSON, Generics Meghan Cowan POSIX Family of standards specified by the IEEE Maintains compatibility across variants of Unix-like OS Defines API and standards for basic I/O: file, terminal

More information

Everything Else C Programming and Software Tools. N.C. State Department of Computer Science

Everything Else C Programming and Software Tools. N.C. State Department of Computer Science Everything Else C Programming and Software Tools N.C. State Department of Computer Science BOOLEANS CSC230: C and Software Tools NC State University Computer Science Faculty 2 Booleans In C99, bools are

More information

The C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and

The C Programming Language Part 4. (with material from Dr. Bin Ren, William & Mary Computer Science, and The C Programming Language Part 4 (with material from Dr. Bin Ren, William & Mary Computer Science, and www.cpp.com) 1 Overview Basic Concepts of Pointers Pointers and Arrays Pointers and Strings Dynamic

More information

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals CS213 Exceptional Control Flow Part II Topics Process Hierarchy Signals ECF Exists at All Levels of a System Exceptions Hardware and operating system kernel software Concurrent processes Hardware timer

More information

Other Interprocess communication (Chapter 2.3.8, Tanenbaum)

Other Interprocess communication (Chapter 2.3.8, Tanenbaum) Other Interprocess communication (Chapter 2.3.8, Tanenbaum) IPC Introduction Cooperating processes need to exchange information, as well as synchronize with each other, to perform their collective task(s).

More information

Introduction to Socket Programming

Introduction to Socket Programming Introduction to Socket Programming Sandip Chakraborty Department of Computer Science and Engineering, INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR March 21, 2017 Sandip Chakraborty (IIT Kharagpur) CS 39006

More information

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter

1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 1 /* client.c - adapted from code for example client program that uses TCP */ 2 /*Modified by Vincent Chu, Winter 2004. 3 http://www.sfu.ca/~vwchu 4 chuvincent (at) gmail (dot) com 5 */ 6 7 #define closesocket

More information

Εργαστήριο 9 I/O Multiplexing

Εργαστήριο 9 I/O Multiplexing Εργαστήριο 9 I/O Multiplexing Στοεργαστήριοθαμελετηθούν: Server High Level View I/O Multiplexing Solutions for Concurrency nonblocking I/O Use alarm and signal handler to interrupt slow system calls. Use

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST 2011 EXAMINATIONS CSC 209H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: one two-sided 8.5x11

More information

More Network Programming

More Network Programming More Network Programming More Network Programming HTTP push server Request framing and server push concepts Demo Useful API s select/poll and advanced sockets tidbits threads HTTP push server code Components

More information

ECE264 Spring 2013 Final Exam, April 30, 2013

ECE264 Spring 2013 Final Exam, April 30, 2013 ECE264 Spring 2013 Final Exam, April 30, 2013 In signing this statement, I hereby certify that the work on this exam is my own and that I have not copied the work of any other student while completing

More information

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort

Maria Hybinette, UGA. ! One easy way to communicate is to use files. ! File descriptors. 3 Maria Hybinette, UGA. ! Simple example: who sort Two Communicating Processes Hello Gunnar CSCI 6730/ 4730 Operating Systems Process Chat Maria A Hi Nice to Hear from you Process Chat Gunnar B Dup & Concept that we want to implement 2 On the path to communication

More information