Remote Procedure Call Part 2
|
|
- Georgiana Oliver
- 6 years ago
- Views:
Transcription
1 Remote Procedure Call Part 2 York University COSC4213
2 The XDR File In our example, the only declared type is a structure with one integer filed and one character filed. rdict_xdr.c contains the code needed to convert a structure of type example from the native representation to the external data representation. If one of the remote procedures did use the an example structure, rpcgen would generate code in both client and server to call xdr_example to convert the representation.
3 Client code (rdict_clnt.c) /* * Please do not edit this file. * It was generated using rpcgen */ #include "rdict.h" #ifndef _KERNEL #include <stdio.h> #include <stdlib.h> /* getenv, exit */ #endif /*!_KERNEL */ /* Default timeout can be changed using clnt_control() */ static struct timeval TIMEOUT = 25, 0 ; int * initw_1(argp, clnt) void *argp; CLIENT *clnt; static int clnt_res; memset((char *)&clnt_res, 0, sizeof (clnt_res)); if (clnt_call(clnt, INITW, (xdrproc_t) xdr_void, (caddr_t) argp, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)!= RPC_SUCCESS) return (NULL); return (&clnt_res);
4 Client code (rdict_clnt.c) int * insertw_1(argp, clnt) char **argp; CLIENT *clnt; static int clnt_res; memset((char *)&clnt_res, 0, sizeof (clnt_res)); if (clnt_call(clnt, INSERTW, (xdrproc_t) xdr_wrapstring, (caddr_t) argp, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)!= RPC_SUCCESS) return (NULL); return (&clnt_res);
5 Client code (rdict_clnt.c) int * deletew_1(argp, clnt) char **argp; CLIENT *clnt; static int clnt_res; memset((char *)&clnt_res, 0, sizeof (clnt_res)); if (clnt_call(clnt, DELETEW, (xdrproc_t) xdr_wrapstring, (caddr_t) argp, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)!= RPC_SUCCESS) return (NULL); return (&clnt_res);
6 Client code (rdict_clnt.c) int * lookupw_1(argp, clnt) char **argp; CLIENT *clnt; static int clnt_res; memset((char *)&clnt_res, 0, sizeof (clnt_res)); if (clnt_call(clnt, LOOKUPW, (xdrproc_t) xdr_wrapstring, (caddr_t) argp, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)!= RPC_SUCCESS) return (NULL); return (&clnt_res);
7 Server Code (rdict_svc.c) * Please do not edit this file. * It was generated using rpcgen. */ #include "rdict.h" #include <stdio.h> #include <stdlib.h> /* getenv, exit */ #include <signal.h> #include <sys/types.h> #include <memory.h> #include <stropts.h> #include <netconfig.h> #include <sys/resource.h> /* rlimit */ #include <syslog.h> #ifdef DEBUG #define #endif RPC_SVC_FG #define _RPCSVC_CLOSEDOWN 120 static int _rpcpmstart; /* Started by a port monitor? */
8 Server Code (rdict_svc.c) /* States a server can be in wrt request */ #define _IDLE 0 #define _SERVED 1 static int _rpcsvcstate = _IDLE; /* Set when a request is serviced */ static int _rpcsvccount = 0; /* Number of requests being serviced */ static void _msgout(msg) char *msg; #ifdef RPC_SVC_FG if (_rpcpmstart) syslog(log_err, msg); else (void) fprintf(stderr, "%s\n", msg); #else syslog(log_err, msg); #endif
9 Server Code (rdict_svc.c) static void closedown(sig) int sig; if (_rpcsvcstate == _IDLE && _rpcsvccount == 0) int size; int i, openfd = 0; else size = svc_max_pollfd; for (i = 0; i < size && openfd < 2; i++) if (svc_pollfd[i].fd >= 0) openfd++; if (openfd <= 1) exit(0); _rpcsvcstate = _IDLE; (void) signal(sigalrm, (void(*)()) closedown); (void) alarm(_rpcsvc_closedown/2);
10 Server Code (rdict_svc.c) static void rdictprog_1(rqstp, transp) struct svc_req *rqstp; register SVCXPRT *transp; union char *insertw_1_arg; char *deletew_1_arg; char *lookupw_1_arg; argument; char *result; bool_t (*_xdr_argument)(), (*_xdr_result)(); char *(*local)(); _rpcsvccount++; switch (rqstp->rq_proc) case NULLPROC: (void) svc_sendreply(transp, xdr_void, (char *)NULL); _rpcsvccount--; _rpcsvcstate = _SERVED; return;
11 Server Code (rdict_svc.c) case INITW: _xdr_argument = xdr_void; _xdr_result = xdr_int; local = (char *(*)()) initw_1; break; case INSERTW: _xdr_argument = xdr_wrapstring; _xdr_result = xdr_int; local = (char *(*)()) insertw_1; break; case DELETEW: _xdr_argument = xdr_wrapstring; _xdr_result = xdr_int; local = (char *(*)()) deletew_1; break; case LOOKUPW: _xdr_argument = xdr_wrapstring; _xdr_result = xdr_int; local = (char *(*)()) lookupw_1; break;
12 Server Code (rdict_svc.c) default: svcerr_noproc(transp); _rpcsvccount--; _rpcsvcstate = _SERVED; return;
13 Server Code (rdict_svc.c) (void) memset((char *)&argument, 0, sizeof (argument)); if (!svc_getargs(transp, _xdr_argument, (caddr_t) &argument)) svcerr_decode(transp); _rpcsvccount--; _rpcsvcstate = _SERVED; return; result = (*local)(&argument, rqstp); if (result!= NULL &&!svc_sendreply(transp, _xdr_result, result)) svcerr_systemerr(transp); if (!svc_freeargs(transp, _xdr_argument, (caddr_t) &argument)) _msgout("unable to free arguments"); exit(1); _rpcsvccount--; _rpcsvcstate = _SERVED; return;
14 Server Code (rdict_svc.c) main() pid_t pid; int i; (void) sigset(sigpipe, SIG_IGN); /* * If stdin looks like a TLI endpoint, we assume * that we were started by a port monitor. If * t_getstate fails with TBADF, this is not a * TLI endpoint. */ if (t_getstate(0)!= -1 t_errno!= TBADF) char *netid; struct netconfig *nconf = NULL; SVCXPRT *transp; int pmclose; _rpcpmstart = 1; openlog("rdict", LOG_PID, LOG_DAEMON);
15 Server Code (rdict_svc.c) if ((netid = getenv("nlsprovider")) == NULL) /* started from inetd */ pmclose = 1; else if ((nconf = getnetconfigent(netid)) == NULL) _msgout("cannot get transport info"); RDICTVERS)."); pmclose = (t_getstate(0)!= T_DATAXFER); if ((transp = svc_tli_create(0, nconf, NULL, 0, 0)) == NULL) _msgout("cannot create server handle"); exit(1); if (nconf) freenetconfigent(nconf); if (!svc_reg(transp, RDICTPROG, RDICTVERS, rdictprog_1, 0)) _msgout("unable to register (RDICTPROG, exit(1);
16 Server Code (rdict_svc.c) if (pmclose) (void) signal(sigalrm, (void(*)()) closedown); (void) alarm(_rpcsvc_closedown/2); svc_run(); exit(1); /* NOTREACHED */ else #ifndef RPC_SVC_FG int size; struct rlimit rl; pid = fork(); if (pid < 0) perror("cannot fork"); exit(1);
17 Server Code (rdict_svc.c) #endif if (pid) exit(0); rl.rlim_max = 0; getrlimit(rlimit_nofile, &rl); if ((size = rl.rlim_max) == 0) exit(1); for (i = 0; i < size; i++) (void) close(i); i = open("/dev/null", 2); (void) dup2(i, 1); (void) dup2(i, 2); setsid(); openlog("rdict", LOG_PID, LOG_DAEMON);
18 Server Code (rdict_svc.c) if (!svc_create(rdictprog_1, RDICTPROG, RDICTVERS, "netpath")) _msgout("unable to create (RDICTPROG, RDICTVERS) for netpath."); exit(1); svc_run(); _msgout("svc_run returned"); exit(1); /* NOTREACHED */
19 Server Code (rdict_svc.c) Rpcgen produces the file rdict_svc.c The file contain the main program that execute when the server begins. It obtains a protocol port, registers the RPC program with the port mapper, and then waits to receive RPC calls. cc c rdict_clnt.c cc c rdict_svc.c cc c rdict_xdr.c
20 Step 5 Write Stub Interface Procedures On the client side, it calls interface procedures using the same procedure names and argument types as the original program (non RPC). On the server side, the interface routines accept calls from the communication stubs that RPC produces, and pass control to the procedure Must translate from XDR to native
21 Rdict_cif.c /* rdict_cif.c - initw, insertw, deletew, lookupw */ #include <rpc/rpc.h> #include <stdio.h> #include "rdict.h" /* Client-side stub interface routines written by programmer */ extern CLIENT *handle; /* handle for remote procedure */ static int *ret; /* tmp storage for return code */ /* * initw - client interface routine that calls initw_1 * */ int initw() ret = initw_1(0, handle); return ret==0? 0 : *ret;
22 Rdict_cif.c /* * insertw - client interface routine that calls insertw_1 * */ int insertw(char *word) char **arg; /* pointer to argument */ arg = &word; ret = insertw_1(arg, handle); return ret==0? 0 : *ret; /* * deletew - client interface routine that calls deletew_1 * */ int deletew(char *word) char **arg; /* pointer to argument */ arg = &word; ret = deletew_1(arg, handle); return ret==0? 0 : *ret;
23 Rdict_cif.c /* * lookupw - client interface routine that calls lookupw_1 * */ int lookupw(char *word) char **arg; /* pointer to argument */ arg = &word; ret = lookupw_1(arg, handle); return ret==0? 0 : *ret;
24 Rdict_sif.c /* rdict_sif.c - init_1, insert_1, delete_1, lookup_1 */ #include <rpc/rpc.h> #include "rdict.h" /* Server-side stub inteface routines written by programmer */ static int retcode; /* * insertw_1 - server side interface to remote procedure insertw * */ int * insertw_1(char **w) retcode = insertw(*w); return &retcode;
25 Rdict_sif.c /* * initw_1 - server side interface to remote procedure initw * */ int * initw_1() retcode = initw(); return &retcode; /* * deletew_1 - server side interface to remote procedure deletew * */ int * deletew_1(char **w) retcode = deletew(*w); return &retcode;
26 Rdict_sif.c /* * lookupw_1 - server side interface to remote procedure lookupw * */ int * lookupw_1(char **w) retcode = lookupw(*w); return &retcode;
27 Step 6 We need some changes in the origianl rdict.c program
28 Rdict.c /* rdict.c - main, nextin */ #include <rpc/rpc.h> #include <stdlib.h> #include <stdio.h> #include <ctype.h> #include "rdict.h" #define MAXWORD 50 /* maximum length of a command or word */ #define RMACHINE "localhost" /* name of remote machine */ CLIENT *handle; /* handle for remote procedure */ int int nextin(char *cmd, char *word), initw(), insertw(char *word); deletew(char *word), lookupw(char *word);
29 Rdict.c /* * main - insert, delete, or lookup words in a dictionary as specified * */ int main(int argc, char *argv[]) char word[maxword+1]; /* space to hold word from input line */ char cmd; int wrdlen; /* length of input word */ /* set up connection for remote procedure call */ handle = clnt_create(rmachine, RDICTPROG, RDICTVERS, "tcp"); if (handle == 0) printf("could not contact remote program.\n"); exit(1);
30 Rdict.c while (1) wrdlen = nextin(&cmd, word); if (wrdlen < 0) exit(0); switch (cmd) case 'I': /* "initialize" */ initw(); printf("dictionary initialized to empty.\n"); break; case 'i': /* "insert" */ insertw(word); printf("%s inserted.\n",word); break; case 'd': /* "delete" */ if (deletew(word)) printf("%s deleted.\n",word); else printf("%s not found.\n",word); break;
31 Rdict.c case 'l': /* "lookup" */ if (lookupw(word)) printf("%s was found.\n",word); else printf("%s was not found.\n",word); break; case 'q': /* quit */ printf("program quits.\n"); exit(0); default: /* illegal input */ printf("command %c invalid.\n", cmd); break;
32 Rdict.c /* * nextin - read a command and (possibly) a word from the next input line * */ int nextin(char *cmd, char *word) int i, ch; ch = getc(stdin); while (isspace(ch)) ch = getc(stdin); if (ch == EOF) return -1; *cmd = (char) ch; ch = getc(stdin); while (isspace(ch)) ch = getc(stdin); if (ch == EOF) return -1; if (ch == '\n') return 0; i = 0;
33 Rdict.c while (!isspace(ch)) if (++i > MAXWORD) printf("error: word too long.\n"); exit(1); *word++ = ch; ch = getc(stdin); *word = \0 ; return i;
34 Step 6 Now compile the client program cc c rdict.c cc rdict_cif.c cc o rdict rdict.o rdict_clnt.o rdict_xdr.o rdict_cif.o lnsl -lsocket
35 Step 7 Now, the server program It contains all the procedures we need.
36 Rdict_srp.c /* rdict_srp.c - initw, insertw, deletew, lookupw */ #include <rpc/rpc.h> #include "rdict.h" /* Server-side remote procedures and the global data they use */ char dict[dictsiz][maxword+1];/* storage for a dictionary of words */ int nwords = 0; /* number of words in the dictionary */ /* * initw - initialize the dictionary to contain no words at all * */ int initw() nwords = 0; return 1;
37 Rdict_srp.c /* * insertw - insert a word in the dictionary * */ int insertw(char *word) strcpy(dict[nwords], word); nwords++; return nwords; /* * deletew - delete a word from the dictionary * */ int deletew(char *word) int i; for (i=0 ; i<nwords ; i++) if (strcmp(word, dict[i]) == 0) nwords--; strcpy(dict[i], dict[nwords]); return 1; return 0;
38 Rdict_srp.c /* * lookupw - look up a word in the dictionary * */ int lookupw(char *word) int i; for (i=0 ; i<nwords ; i++) if (strcmp(word, dict[i]) == 0) return 1; return 0;
39 Step 7 Compile and run the server program cc c rdict_srp.c cc o rdictd rdict_svc.o rdict_xdr.o rdict_sif.o rdict_srp.o lnsl lsocket
40 Step 8 Run the server on the remote machine./rdictd & There is a makefile that you can use to handle all the compilation You have to specify instead of localhost the name of the machine the server will be running on
RPC Programming. Some knowledge of C & Unix A network with at least two connected machines.
RPC Programming 1.0 Prerequisites Some knowledge of C & Unix A network with at least two connected machines. 2.0 Objectives: 1. To understand the basic principles of RPC 2. To develop a program which returns
More informationInter-process Communication: RPC
Inter-process Communication: RPC Dr. Yong Guan Department of Electrical and Computer Engineering & Information Assurance Center Iowa State University Outline for Today s Talk Inter-process Communication:
More informationLecture 12 RPC RPC RPC. Writing an RPC Program. Sun RPC RPC. February 9+11, 2005
RPC Lecture 12 RPC February 9+11, 2005 Remote Procedure Call Follows application-oriented approach (emphasizes problem over communication) Design program and then divide it. RPC RPC There exists a way
More informationProgramming Using Sun TI-RPC to develop distributed applications
System i Programming Using Sun TI-RPC to develop distributed applications Version 5 Release 4 System i Programming Using Sun TI-RPC to develop distributed applications Version 5 Release 4 Note Before
More informationProcess Concept: views of a process Process Scheduling CSCI 6730/ 4730 Operating Systems
Chapter 3: Processes: Outline Process Concept: views of a process Process Scheduling CSCI 6730/ 4730 Operating Systems Operations on Processes Cooperating Processes Inter Process Communication (IPC) RPC:
More informationChapter 3: Processes: Outline. Operating Systems. Remote Procedure Calls (RPC) Client-Server Remote Machine Communication Mechanisms
Chapter 3: Processes: Outline Operating Systems RPC: Processes Process Concept: views of a process Process Scheduling Operations on Processes Cooperating Processes Inter Process Communication (IPC) Local
More informationTonight. Communication. Middleware Protocols. Remote Procedure Call (RPC) Several common communication mechanisms RPC RMI Sockets Next week: HTTP,
Tonight Communication Tanenbaum Ch. 4 Distributed Software Systems CS 707 Several common communication mechanisms RPC RMI Sockets Next week: HTTP, Middleware Protocols Remote Procedure Call (RPC) Figure
More informationRemote Procedure Call
Remote Procedure Call Outline Concept of RPC SunRPC Spring 2009 CSE30264 1 RPC Timeline Server Request Blocked Blocked Reply Computing Blocked Spring 2009 CSE30264 2 RPC There exists a way for processes
More informationSun Remote Procedure Call Mechanism
Sun Remote Procedure Call Mechanism Originally developed by Sun, but now widely available on other platforms (including Digital Unix). Also known as Open Network Computing (ONC). Sun RPC package has an
More informationDesarrollo de Aplicaciones en Red. El modelo de comunicación. General concepts. Models of communication. Message Passing
Desarrollo de Aplicaciones en Red El modelo de comunicación José Rafael Rojano Cáceres http://www.uv.mx/rrojano 1 2 General concepts As we saw in a Distributed System the logical and physical component
More informationPrograms. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems
Programs CSCI 4061 Introduction to Operating Systems C Program Structure Libraries and header files Compiling and building programs Executing and debugging Instructor: Abhishek Chandra Assume familiarity
More informationRemote Procedure Calls (RPC)
Distributed Computing Remote Procedure Calls (RPC) Dr. Yingwu Zhu Problems with Sockets Sockets interface is straightforward [connect] read/write [disconnect] BUT it forces read/write mechanism We usually
More informationDistributed Program Design Typical Sockets Approach. Remote Procedure Call. Remote Subroutine
Distributed Program Design Typical Sockets Approach Communication-Oriented Design Design protocol first. Build programs that adhere to the protocol. Application-Oriented Design Build application(s). Divide
More informationWeek 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430
Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on
More informationCS 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 informationSOFTWARE Ph.D. Qualifying Exam Spring Consider the following C program which consists of two function definitions including the main function.
(i) (5 pts.) SOFTWARE Ph.D. Qualifying Exam Spring 2018 Consider the following C program which consists of two function definitions including the main function. #include int g(int z) { int y
More informationRemote Procedure Calls, TLI, STREAMS
Remote Procedure Calls, TLI, STREAMS 13 RPC, TLI, STREAMS Hannes Lubich, 2003 2005 Page 1 Goals of this Lecture Understand the design of remote procedure calls in general and the design and programming
More informationCS 350 : COMPUTER SYSTEM CONCEPTS SAMPLE TEST 2 (OPERATING SYSTEMS PART) Student s Name: MAXIMUM MARK: 100 Time allowed: 70 minutes
CS 350 : COMPUTER SYSTEM CONCEPTS SAMPLE TEST 2 (OPERATING SYSTEMS PART) Student s Name: MAXIMUM MARK: 100 Time allowed: 70 minutes Q1 (30 marks) NOTE: Unless otherwise stated, the questions are with reference
More informationCompile the Hello World program
OS Project1 1 Hello World Writing a Hello World program #include header.h main ( int argc, char *argv[] ) { printf( Hello World!\n ); } Compile the Hello World program > gcc helloworld.c o helloworld 2
More informationCSE 660 Lab 2 Khoi Pham Thanh Ho April 27 th, 2015
CSE 660 Lab 2 Khoi Pham Thanh Ho April 27 th, 2015 Comment and Evaluation: This lab focuses on two ways to call a function from Client to Server: Remote Procedure Call (RPC) is basic method in C for Server
More informationDistributed-Memory Programming Models IV
Distributed-Memory Programming Models IV Stefan Lang Interdisciplinary Center for Scientific Computing (IWR) University of Heidelberg INF 368, Room 532 D-69120 Heidelberg phone: 06221/54-8264 email: Stefan.Lang@iwr.uni-heidelberg.de
More information518 Lecture Notes Week 3
518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management
More informationFriday, September 16, Lab Notes. Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week
Friday, September 16, 2016 Lab Notes Topics for today Redirection of input and output Command line arguments More pre-processor options Programs: Finish Program 1, begin Program 2 due next week 1. Redirection
More informationComputer 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 informationFriday, February 10, Lab Notes
Friday, February 10, 2017 Lab Notes Topics for today Structures in C Redirection of input and output in a Unix-like environment Command line arguments More pre-processor options Programs: Finish Program
More informationLesson 6.1: Structs. This declares a collection of two integer variables to denote the two coordinates of a point in a plane.
Lesson 6.1: Structs Programming in C Prof. Dr. Eike Best Dr. Elke Wilkeit October 12, 2002 1 struct point { 2 int x; 3 int y; 4 }; This declares a collection of two integer variables to denote the two
More informationPrinceton University COS 333: Advanced Programming Techniques A Subset of C90
Princeton University COS 333: Advanced Programming Techniques A Subset of C90 Program Structure /* Print "hello, world" to stdout. Return 0. */ { printf("hello, world\n"); -----------------------------------------------------------------------------------
More informationPreview. Process Control. What is process? Process identifier The fork() System Call File Sharing Race Condition. COSC350 System Software, Fall
Preview Process Control What is process? Process identifier The fork() System Call File Sharing Race Condition COSC350 System Software, Fall 2015 1 Von Neumann Computer Architecture: An integrated set
More informationFile Access. FILE * fopen(const char *name, const char * mode);
File Access, K&R 7.5 Dealing with named files is surprisingly similar to dealing with stdin and stdout. Start by declaring a "file pointer": FILE *fp; /* See Appendix B1.1, pg. 242 */ header
More informationBinary Search Tree 1.0. Generated by Doxygen Mon Jun :12:39
Binary Search Tree 1.0 Generated by Doxygen 1.7.1 Mon Jun 6 2011 16:12:39 Contents 1 Binary Search Tree Program 1 1.1 Introduction.......................................... 1 2 Data Structure Index 3
More informationDiscussion of Assignments 2. Line buffered vs. full buffered I/O. Some often encountered issues in the submissions.
3 4 Discussion of Assignment 1 Discussion of Assignments 1 and 2 Accompanying Tutorial to Operating Systems Course Alexander Holupirek, Stefan Klinger Database and Information Systems Group Department
More informationUnix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.
Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both
More information03 Remote invocation. Request-reply RPC. Coulouris 5 Birrel_Nelson_84.pdf RMI
03 Remote invocation Request-reply RPC Coulouris 5 Birrel_Nelson_84.pdf RMI 2/16 Remote Procedure Call Implementation client process Request server process client program client stub procedure Communication
More informationBasic 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 informationCSCI-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 informationCSC 1600 Unix Processes. Goals of This Lecture
CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process
More informationHomework 2 Answers. Due Date: Monday, April 29, 2002, at 11:59PM Points: 100
Homework 2 Answers Due Date: Monday, April 29, 2002, at 11:59PM Points: 100 UNIX System 1. (10 points) What program is running as process #1? Type ps ax and look for the process with a PID of 1. Then look
More informationRemote Procedure Call Implementations
Remote Procedure Call Implementations Sun ONC(Open Network Computing) RPC. Implements at-most-once semantics by default. At-least-once (idempotent) can also be chosen as an option for some procedures.
More informationFall 2015 COMP Operating Systems. Lab #3
Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute
More informationTutorial 1: Introduction to C Computer Architecture and Systems Programming ( )
Systems Group Department of Computer Science ETH Zürich Tutorial 1: Introduction to C Computer Architecture and Systems Programming (252-0061-00) Herbstsemester 2012 Goal Quick introduction to C Enough
More informationPRINCIPLES OF OPERATING SYSTEMS
PRINCIPLES OF OPERATING SYSTEMS Tutorial-1&2: C Review CPSC 457, Spring 2015 May 20-21, 2015 Department of Computer Science, University of Calgary Connecting to your VM Open a terminal (in your linux machine)
More informationPiotr Mielecki Ph. D.
Piotr Mielecki Ph. D. http://mielecki.ristel.pl/ piotr.mielecki@pwr.edu.pl pmielecki@gmail.com Building blocks of client-server applications: Client, Server, Middleware. Simple client-server application:
More informationFinal Precept: Ish. Slides Originally Prepared by: Wonho Kim
Final Precept: Ish Slides Originally Prepared by: Wonho Kim Agenda Last time exec(), fork() wait() Today zombie, orphan process built-in commands in ish I/O redirection Unix signal Process Hierarchy Every
More informationDeep 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 informationFile IO and command line input CSE 2451
File IO and command line input CSE 2451 File functions Open/Close files fopen() open a stream for a file fclose() closes a stream One character at a time: fgetc() similar to getchar() fputc() similar to
More informationKurt 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 informationPipes. Pipes Implement a FIFO. Pipes (cont d) SWE 545. Pipes. A FIFO (First In, First Out) buffer is like a. Pipes are uni-directional
Pipes SWE 545 Pipes Pipes are a way to allow processes to communicate with each other Pipes implement one form of IPC (Interprocess Communication) This allows synchronization of process execution There
More informationDept. of Computer Science & Engineering 1 Knowledge & Data Engineering Lab.
Process Part2 Dept. of Computer Science & Engineering 1 Process Attributes Process ID Process groups and process group ID Environment Current working and root directory User and group ID Process Priorities
More informationSignal Example 1. Signal Example 2
Signal Example 1 #include #include void ctrl_c_handler(int tmp) { printf("you typed CTL-C, but I don't want to die!\n"); int main(int argc, char* argv[]) { long i; signal(sigint, ctrl_c_handler);
More informationCS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20
CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to
More information8. Characters, Strings and Files
REGZ9280: Global Education Short Course - Engineering 8. Characters, Strings and Files Reading: Moffat, Chapter 7, 11 REGZ9280 14s2 8. Characters and Arrays 1 ASCII The ASCII table gives a correspondence
More informationCS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.
CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to
More informationCSC Execution Environment. Program Execution Environment
CSC 1600 Program Execution Environment Execution Environment The main func*on is the entry point for C program execu*on int main( int argc, char * argv[]); The linker (called by the C compiler) specifies,
More informationHomework 5. Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100
Homework 5 Due Date: Friday, June 7, 2002, at 11:59PM; no late assignments accepted Points: 100 UNIX System 1. (10 points) I want to make the file libprog.a in my home directory available to everyone so
More informationRicardo 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 informationHere's how you declare a function that returns a pointer to a character:
23 of 40 3/28/2013 10:35 PM Violets are blue Roses are red C has been around, But it is new to you! ANALYSIS: Lines 32 and 33 in main() prompt the user for the desired sort order. The value entered is
More informationCSC209H Lecture 3. Dan Zingaro. January 21, 2015
CSC209H Lecture 3 Dan Zingaro January 21, 2015 Streams (King 22.1) Stream: source of input or destination for output We access a stream through a file pointer (FILE *) Three streams are available without
More informationELEC 377 C Programming Tutorial. ELEC Operating Systems
ELE 377 Programming Tutorial Outline! Short Introduction! History & Memory Model of! ommon Errors I have seen over the years! Work through a linked list example on the board! - uses everything I talk about
More information1 /* 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 informationUnderstanding Pointers
Division of Mathematics and Computer Science Maryville College Pointers and Addresses Memory is organized into a big array. Every data item occupies one or more cells. A pointer stores an address. A pointer
More informationBIL 104E Introduction to Scientific and Engineering Computing. Lecture 14
BIL 104E Introduction to Scientific and Engineering Computing Lecture 14 Because each C program starts at its main() function, information is usually passed to the main() function via command-line arguments.
More informationRPC Extensions Developer s Guide
RPC Extensions Developer s Guide Sun Microsystems, Inc. 4150 Network Circle Santa Clara, CA 95054 U.S.A. Part No: 816 3576 10 February 2002 Copyright 2002 Sun Microsystems, Inc. 4150 Network Circle, Santa
More informationSoftware Development With Emacs: The Edit-Compile-Debug Cycle
Software Development With Emacs: The Edit-Compile-Debug Cycle Luis Fernandes Department of Electrical and Computer Engineering Ryerson Polytechnic University August 8, 2017 The Emacs editor permits the
More information#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 informationMessage passing systems are popular because they support client-server interactions, where: clients send messages to servers requesting a server.
Client-Server Model Message passing systems are popular because they support client-server interactions, where: clients send messages to servers requesting a server. servers provide services requested
More informationSymbols, Compilation Units, and Pre-Processing
Symbols, Compilation Units, and Pre-Processing Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana March 2, 2015 Outline Compilation process Symbols: compilation units and linking
More informationRPC Remote Procedure Call
RPC Remote Procedure Call Stand-alone program #include long bin_date(void); char *str_date(long bintime); main(int argc, char **argv) { long lresult; /* return from bin_date */ char *sresult;
More informationOperating Systemss and Multicore Programming (1DT089)
Operating Systemss and Multicore Programming (1DT089) Problem Set 1 - Tutorial January 2013 Uppsala University karl.marklund@it.uu.se pointers.c Programming with pointers The init() functions is similar
More informationReview of Scientific Programming in C and Fortran. Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration
Review of Scientific Programming in C and Fortran Michael McLennan Software Architect HUBzero Platform for Scientific Collaboration Monte Carlo Simulator Simulate by randomly generating thousands of tracks?
More informationCS240: Programming in C
CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows
More informationCS113: Lecture 7. Topics: The C Preprocessor. I/O, Streams, Files
CS113: Lecture 7 Topics: The C Preprocessor I/O, Streams, Files 1 Remember the name: Pre-processor Most commonly used features: #include, #define. Think of the preprocessor as processing the file so as
More informationComputational 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 informationVariables Data types Variable I/O. C introduction. Variables. Variables 1 / 14
C introduction Variables Variables 1 / 14 Contents Variables Data types Variable I/O Variables 2 / 14 Usage Declaration: t y p e i d e n t i f i e r ; Assignment: i d e n t i f i e r = v a l u e ; Definition
More informationBasic C Programming. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island
Basic C Programming Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island Announcements Exam 1 (20%): Feb. 27 (Tuesday) Tentative Proposal Deadline:
More informationLesson 5: Functions and Libraries. EE3490E: Programming S1 2018/2019 Dr. Đào Trung Kiên Hanoi Univ. of Science and Technology
Lesson 5: Functions and Libraries 1 Functions 2 Overview Function is a block of statements which performs a specific task, and can be called by others Each function has a name (not identical to any other),
More informationCSci Introduction to Distributed Systems. Communication: RPC In Practice
CSci 5105 Introduction to Distributed Systems Communication: RPC In Practice Linux RPC Language-neutral RPC Can use Fortran, C, C++ IDL compiler rpgen N to generate all stubs, skeletons (server stub) Example:
More informationCS 0449 Sample Midterm
Name: CS 0449 Sample Midterm Multiple Choice 1.) Given char *a = Hello ; char *b = World;, which of the following would result in an error? A) strlen(a) B) strcpy(a, b) C) strcmp(a, b) D) strstr(a, b)
More informationMidterm Exam Nov 8th, COMS W3157 Advanced Programming Columbia University Fall Instructor: Jae Woo Lee.
Midterm Exam Nov 8th, 2012 COMS W3157 Advanced Programming Columbia University Fall 2012 Instructor: Jae Woo Lee About this exam: - There are 4 problems totaling 100 points: problem 1: 30 points problem
More informationCS 3305 Intro to Threads. Lecture 6
CS 3305 Intro to Threads Lecture 6 Introduction Multiple applications run concurrently! This means that there are multiple processes running on a computer Introduction Applications often need to perform
More informationCOP Programming Concepts Spring 1999 CLOSED BOOK Exam #1 100 Points NAME
CLOSED BOOK Exam #1 100 Points NAME 1. The following program has (at least) 10 syntax errors. Circle each error. Write the corrected program in the blank space below. 2 points for each error you find.
More informationOperating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm
Operating Systems Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) armahmood786@yahoo.com alphasecure@gmail.com alphapeeler.sf.net/pubkeys/pkey.htm http://alphapeeler.sourceforge.net pk.linkedin.com/in/armahmood
More informationCSE 333 Midterm Exam July 24, 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 informationHigh-performance computing and programming Intro to C on Unix/Linux. Uppsala universitet
High-performance computing and programming Intro to C on Unix/Linux IT Uppsala universitet What is C? An old imperative language that remains rooted close to the hardware C is relatively small and easy
More informationunsigned char memory[] STACK ¼ 0x xC of address space globals function KERNEL code local variables
Graded assignment 0 will be handed out in section Assignment 1 Not that bad Check your work (run it through the compiler) Factorial Program Prints out ENTERING, LEAVING, and other pointers unsigned char
More informationProcesses. 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 informationArray Initialization
Array Initialization Array declarations can specify initializations for the elements of the array: int primes[10] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ; initializes primes[0] to 2, primes[1] to 3, primes[2]
More informationSystem Programming. Process Control II
Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Terminating a process
More informationP.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 informationDynamic memory allocation (malloc)
1 Plan for today Quick review of previous lecture Array of pointers Command line arguments Dynamic memory allocation (malloc) Structures (Ch 6) Input and Output (Ch 7) 1 Pointers K&R Ch 5 Basics: Declaration
More informationSystem Models and Communication
System Models and Communication http://idc.hust.edu.cn/~rxli/ Outline Terminology Client-Server Model OSI Model vs. Middleware Model Summary Ruixuan Li School of Computer Science and Technology Huazhong
More informationProcesses. Johan Montelius KTH
Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other
More informationOperating Systems Lab
Operating Systems Lab Islamic University Gaza Engineering Faculty Department of Computer Engineering Fall 2012 ECOM 4010: Operating Systems Lab Eng: Ahmed M. Ayash Lab # 3 Fork() in C and C++ programming
More informationWindows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.
Structure Unix architecture users Functions of the System tools (shell, editors, compilers, ) standard library System call Standard library (printf, fork, ) OS kernel: processes, memory management, file
More informationSyntax Analysis Part VIII
Syntax Analysis Part VIII Exercises: Bison Text adapted from : Marinella Sciortino, Università di Palermo Exercise I Write an interpreter for hand calculator with the following operators +, - (binary)
More informationECE264 Spring 2014 Exam 2, March 11, 2014
ECE264 Spring 2014 Exam 2, March 11, 2014 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 informationTHE UNIVERSITY OF WESTERN ONTARIO. COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER HOURS
Computer Science 211a Final Examination 17 December 2002 Page 1 of 17 THE UNIVERSITY OF WESTERN ONTARIO LONDON CANADA COMPUTER SCIENCE 211a FINAL EXAMINATION 17 DECEMBER 2002 3 HOURS NAME: STUDENT NUMBER:
More informationA process. the stack
A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes
More informationPrepared by Prof. Hui Jiang (COSC3221) 2/9/2007
1 * * ' &% $ # " "! 4 ' Prepared by Prof Hui Jiang COSC1 /9/007 / 0 How CPU is used? Users run programs in CPU In a multiprogramming system a CPU always has several jobs to run How to define a CPU job?
More informationLecture 7: Files. opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments
Lecture 7: Files opening/closing files reading/writing strings reading/writing numbers (conversion to ASCII) command line arguments Lecture 5: Files, I/O 0IGXYVI*MPIW 0 opening/closing files reading/writing
More informationCSci 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