Appendix a Shell Metacharacters

Total Page:16

File Type:pdf, Size:1020Kb

Appendix a Shell Metacharacters Appendix A Shell Metacharacters > Output redirection >> Output append < Input redirection << Input from a here document I Pipe symbol && 'And if' symbol (a && b: run a and if successful run b) II 'Or if' symbol (a II b: run a and if unsucessful run b) .. Case delimiter " Command separator ' ' Command substitution ( ) Command grouping and running of commands in a sub-shell * Match any character ? Match any single character [ .. ] Match any of the enclosed characters \ Quote next character " " Quote the enclosed characters except for $, ", ', \ ' ' Quote the enclosed character except for ' $0 Name of invoking shell script $1 , .. $9 Arguments to shell script $name Value of variable name ${name} Substitution of variable name 187 Appendix B Comparison of Bourne Shell and C Shell Constructs Bourne shell C shell if condition if (condition) then then statement (s) statements elif condition else if (condition) then then statements statements else else statements statements fi end if times time for name [in word-list] foreach name [word-list] do statement (s) statement (s) end done case word in switch (word) option ) crnds;; case option: crnds breaksw * crnds;; default: cmds breaksw esac endsw exit [expr ] exit [ (expr)] export setenv trap 'crnds' signals onintr label • filename source filename continue continue while condition while (condition) do statements statements end done read readonly break [n] break [break] 189 Appendix C ASCII Tables The two tables below show the octal and hexadecimal equivalents of each ASCII character. Table C.l. ASCII character conversion chart (octal) 000 nul 001 sch 002 stx 003 etx 004 ect 005 enq 006 ack 007 bel 010 bs 011 ht 012 n1 013 vt 014 np 015 cr 016 so 017 si 020 dle 021 del 022 dc2 023 dc3 024 dc4 025 nak 026 syn 027 etb 030 can 031 ern 032 sub 033 esc 034 fs 035 gs 036 rs 037 us 040 sp 041 042 II 043 il 044 $ 045 % 046 & 047 I 050 ( 051 ) 052 * 053 + 054 055 - 056 057 I 060 0 061 1 062 2 063 3 064 4 065 5 066 6 067 7 070 8 071 9 072 073 i 074 < 075 = 076 > 077 ? 100 @ 101 A 102 B 103 c 104 D 105 E 106 F 107 G 110H 111 I 112 J 113 K 1141 115M 116N 117 0 120 p 121 Q 122 R 123 s 124 T 125 u 126 v 127 w 130 X 131 y 132 z 133 [ 134 \ 135 l 136 A 137 140 ' 141 a 142 b 143 c 144 d 145 e 146 f 147 g 150 h 151 i 152 j 153 k 154 1 155 rn 156 n 157 0 160 p 161 q 162 r 163 s 164 t 165 u 166 v 167 w 170 X 171 y 172 z 173 { 174 I 175 } 176 ~ 177 del Table C.2. ASCII character conversion chart (hexadecimal) 00 nul 01 soh 02 stx 03 etx 04 eot 05 enq 06 ack 07 bel 08 bs 09 ht Oa n1 Ob vt Oc np Od cr Oe so Of si 10 dle 11 del 12 dc2 13 dc3 14 dc4 15 nak 16 syn 17 etb 18 can 19 ern 1a sub lb esc lc fs ld gs 1e rs lf us 20 sp 21 22 II 23 il 24 $ 25 % 26 & 27 I 28 ( 29 ) 2a * 2b + 2c 1 2d- 2e . 2f I 30 0 31 1 32 2 33 3 34 4 35 5 36 6 37 7 38 8 39 9 3a : 3b i 3c < 3d = 3e > 3f ? 40 @ 41 A 42 B 43 c 44 D 45 E 46 F 47 G 48 H 49 I 4a J 4b K 4c L 4d M 4e N 4f 0 50 p 51 Q 52 R 53 s 54 T 55 u 56 v 57 w 58 X 59 y Sa Z Sb [ Sc \ Sd l Se A Sf 60 ' 61 a 62 b 63 c 64 d 65 e 66 f 67 g 68 h 69 i 6a j- 6b k 6c 1 6d rn 6e n 6f 0 70 p 71q 72 r 73 s 74 t 75 u 76 v 77 w 78 X 79 y 7a z 7b { 7c I 7d } 7e ~ 7f del 191 Index cat 12 /dev/mem 178, 180 cc 21,37, 79,80,81,88 /dev/null 24 cd 10 /etc/checklist 174 cdc 141 /etc/clri 176 chmod 16 /etc/gettydefs 161, 177 close 106 /etc/group 166 cmp 54 /etc/init 153 commands 21 /etc/inittab 161, 177, 153 grouping 21 /etc/mknod 176 substitution 28 /etc/passwd 153, 166 conditional compilation 81 /etc/rc 161 cp 13 /etc/utmp 161 cpio 163 /lost+found 174 cron 146 /unix 168, 178 cu 158 cut 55 adding users 166 admin 136 date 21 alarm 101 dd 165 ar 85 deleting users 168 archiving 163 df 169, 170 at 145 disk utilisation 169 atof 94 du 169, 170 atoi 94 atol 94 echo 28 awk 47,36 ed editor 63 editor 59 background commands 21 elif 32 backing up 163 env 41 boot block 171 environ 43 environment 42, 45 C language 42, 79, 89 execl 96,97 calendar 144 execle 43 case 33 193 194 The UNIX Workshop execlp 96 kernel 4 execv 96 kill 31, 99, 162 exit 95 export 41 ldgetname 179 expr 29,37 ldopen 179 ldtbindex 179 files 8 ldtbread 179 modes 17 ldtbseek 179 file system 18, 171 libraries 85 file system repair 17 4 In 14 filters 5, 25 logging in 6 find 14 logout 7 flag arguments 22 longjmp 103 for 34 lp 13 fork 97 lpstat 13 fsck 174 Is 12,25 function calls 39 mail 142 getnev 43 make 127 grep 53 man 7 mem 178 here document 31 memory management 4 menu development 38 if 32, 36 mesg 143 1-list 172 message queues 110 impure t.s. programs 84 metacharacters 23, 24 init 161, 171, 177 mkdir 11 inode 172 mkfs 173 ipcrm 110 mm 71 ipcs 109 mount 19 isalnum 89 msgctl 112 isalpha 89 msgget 111 isascii 89 msgrcv 112 iscntrl 89 msgsnd 112 isdigit 89 mv 13 isgraph 89 ISL area 173 named pipes 109 islower 89 news 145 isprint 89 nroff 66 ispunct 89 isspace 89 object file 79 isupper 89 od 57 isxdigit 89 optimisation 85 Index 195 paging 4 shmdt 116 password 6 shmget 116 paste 56 signals 29, 99 pause 101 sleep 29 pclose 105 sort 57, 170 pg 12 special characters 6 pipe 105 special files 18 pipelines 25 split 54 pipes 4, 8, 10 sprintf 93 popen 105 sscanf 92 pr 13 sticky bit 17 process 4 strcat 92 profiling 86, 87 strcmp 90 prs 140 strcpy 91 ps 178 strings 90 pure t.s. progrms 84 strip 85 pwd 10 stripping 85 strlen 92 read 29,35 strncat 92 redirection 23 strncmp 91 rm 11 strncpy 91 rmdel 141 suid 16 rmdir 11 super block 171 swap area 171, 173 sact 140 swap space 17 sees 135 swapping 4 sccsdiff 141 sync 162, 173 semaphores 117 system 95 semctl 118 semget 118 tar 164 semop 118 test 29, 32, 33 set 42 tolower 90 setjmp 103 toupper 90 sgid 16 tr 31,55 shared memory 115 trap 30, 35 shell 5,23 commands 21, 28 umask 17 script 6 umount 19 variables 26 unget 141 shmat 116 unnamed pipes 104 shmctl 116 unset 42 196 The UNIX Workshop until 34 wait 29,98 users 15 wall 29, 144 uucp 149 we 53 uulog 157 what 139 uupick 158 while 34, 35 uustat 157 who 23 write 143 vi editor 59 .
Recommended publications
  • Administering Unidata on UNIX Platforms
    C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta UniData Administering UniData on UNIX Platforms UDT-720-ADMU-1 C:\Program Files\Adobe\FrameMaker8\UniData 7.2\7.2rebranded\ADMINUNIX\ADMINUNIXTITLE.fm March 5, 2010 1:34 pm Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Beta Notices Edition Publication date: July, 2008 Book number: UDT-720-ADMU-1 Product version: UniData 7.2 Copyright © Rocket Software, Inc. 1988-2010. All Rights Reserved. Trademarks The following trademarks appear in this publication: Trademark Trademark Owner Rocket Software™ Rocket Software, Inc. Dynamic Connect® Rocket Software, Inc. RedBack® Rocket Software, Inc. SystemBuilder™ Rocket Software, Inc. UniData® Rocket Software, Inc. UniVerse™ Rocket Software, Inc. U2™ Rocket Software, Inc. U2.NET™ Rocket Software, Inc. U2 Web Development Environment™ Rocket Software, Inc. wIntegrate® Rocket Software, Inc. Microsoft® .NET Microsoft Corporation Microsoft® Office Excel®, Outlook®, Word Microsoft Corporation Windows® Microsoft Corporation Windows® 7 Microsoft Corporation Windows Vista® Microsoft Corporation Java™ and all Java-based trademarks and logos Sun Microsystems, Inc. UNIX® X/Open Company Limited ii SB/XA Getting Started The above trademarks are property of the specified companies in the United States, other countries, or both. All other products or services mentioned in this document may be covered by the trademarks, service marks, or product names as designated by the companies who own or market them. License agreement This software and the associated documentation are proprietary and confidential to Rocket Software, Inc., are furnished under license, and may be used and copied only in accordance with the terms of such license and with the inclusion of the copyright notice.
    [Show full text]
  • Linux from Scratch
    Linux From Scratch Version 3.3 Gerard Beekmans Copyright © 1999−2002 by Gerard Beekmans This book describes the process of creating a Linux system from scratch from an already installed Linux distribution, using nothing but the sources of the software that we use. Copyright (c) 1999−2002, Gerard Beekmans All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: • Redistributions in any form must retain the above copyright notice, this list of conditions and the following disclaimer. • Neither the name of "Linux From Scratch" nor the names of its contributors may be used to endorse or promote products derived from this material without specific prior written permission. • Any material derived from Linux From Scratch must contain a reference to the "Linux From Scratch" project. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Dedication This book is dedicated to my loving and supportive wife Beverly Beekmans.
    [Show full text]
  • Session 12C3 a Simplified Interface for Concurrent Processing
    Session 12c3 A Simplified Interface for Concurrent Processing Janet D. Hartman Applied Computer Science Department Illinois State University Normal, IL 61704 Abstract - Teaching the concepts of concurrency is a task library of C functions, the Parallel Library, that can be used requiring an understanding of how the operating system to introduce the concepts of shared memory multiprocessing allocates resources for the processes and how concurrent and message passing, but hide the details of the actual processes may share data. The difficulty of trying to system calls used to implement them. These functions can understand the asynchronous execution behavior of be used to introduce students to the ideas associated with processes is compounded by the need to understand the concurrent processing in many courses, even at the syntax and required parameters for making the system introductory level. The functions are based on the System calls. Providing wrappers for system calls that make more V UNIX system calls for generating processes and intuitive function calls to allocate and manage resources allocating and managing interprocess communication, but can help students understand the issues involved with could easily be modified for similar POSIX functions. shared memory multiprocessing and message passing systems without having to understand the details of the The Parallel Library syntax associated with making the system calls. This paper describes a library of C functions, the Parallel Library, that The Parallel Library contains functions for creating and can be used to introduce the concepts of shared memory terminating processes along with functions for allocating multiprocessing, message passing, and related and managing interprocess communication structures synchronization issues, but hide the details of the actual (shared memory and message queues) along with functions system calls used to implement them.
    [Show full text]
  • The Unix/Linux Library for Semaphore and Shared Memory Manipulation Programmed by B
    The Unix/Linux Library for Semaphore and Shared Memory Manipulation Programmed by B. Chandrasekara (February 2002) and updated by E. Talagrand and J. Brinkmeier (January 2004) 1. Introduction This library provides a set of functional calls (based on Unix/Linux system calls) for semaphore definitions and operations on semaphores and for a shared memory definition and shared memory access. Download from Carmen Cse2431 at Files into your directory the following files: ssem.h, ssem.c, sshm.h and sshm.c. Then obtain ssem.o and sshm.o using the following compilation commands: gcc –o ssem.o –c ssem.c gcc –o sshm.o –c sshm.c For a program that uses semaphores and a shared memory, the header files ssem.h and sshm.h have to be included into the source code as follows: #include "ssem.h" #include "sshm.h" and the following compilation commands is to be used: gcc –o program program.c ssem.o sshm.o When semaphores or sheared memories are not used in the given program, sem.o or sshm.o, respectively, may be omitted from the above commands. 2. Semaphore Definition and Operations a. int sem_create(int key, int initial_value) This function creates a new semaphore and returns a positive integer (but only if successful). The positive integer is a semaphore identifier to be used in other semaphore functions. The parameter key has to contain a unique value, and a six digit integer is recommended. The parameter initial_value should contain the initial value for the semaphore. b. int sem_open(int key) This function opens an existing semaphore and it returns a positive integer (but only if successful).
    [Show full text]
  • Lecture 08: Interprocess Communication I October 21, 2019 CS631-Advancedprogrammingintheunixenvironment Slide2 System V IPC
    CS631-AdvancedProgrammingintheUNIXEnvironment Slide1 CS631 - Advanced Programming in the UNIX Environment Interprocess Communication I Department of Computer Science Stevens Institute of Technology Jan Schaumann [email protected] https://stevens.netmeister.org/631/ Lecture 08: Interprocess Communication I October 21, 2019 CS631-AdvancedProgrammingintheUNIXEnvironment Slide2 System V IPC Three types of asynchronous IPC originating from System V: Semaphores Shared Memory Message Queues All three use IPC structures, referred to by an identifier and a key; all three are (necessarily) limited to communication between processes on one and the same host. Since these structures are not known by name, special system calls (msgget(2), semop(2), shmat(2), etc.) and special userland commands (ipcrm(1), ipcs(1), etc.) are necessary. Lecture 08: Interprocess Communication I October 21, 2019 CS631-AdvancedProgrammingintheUNIXEnvironment Slide3 System V IPC: Semaphores A semaphore is a counter used to provide access to a shared data object for multiple processes. To obtain a shared resource a process needs to do the following: 1. Test semaphore that controls the resource. 2. If value of semaphore > 0, decrement semaphore and use resource; increment semaphore when done 3. If value == 0 sleep until value > 0 Semaphores are obtained using semget(2), properties controlled using semctl(2), operations on a semaphore performed using semop(2). Lecture 08: Interprocess Communication I October 21, 2019 CS631-AdvancedProgrammingintheUNIXEnvironment Slide4
    [Show full text]
  • POSIX-2017 Shell & Utilities Utilities
    POSIX-2017 Shell & Utilities Utilities admin - create and administer SCCS files (DEVELOPMENT) ex - text editor alias - define or display aliases expand - convert tabs to spaces ar - create and maintain library archives expr - evaluate arguments as an expression asa - interpret carriage-control characters false - return false value at - execute commands at a later time fc - process the command history list awk - pattern scanning and processing language fg - run jobs in the foreground basename - return non-directory portion of a pathname file - determine file type batch - schedule commands to be executed in a batch queue find - find files bc - arbitrary-precision arithmetic language fold - filter for folding lines bg - run jobs in the background fort77 - FORTRAN compiler (FORTRAN) c99 - compile standard C programs fuser - list process IDs of all processes that have one or more files cal - print a calendar open cat - concatenate and print files gencat - generate a formatted message catalog cd - change the working directory getconf - get configuration values cflow - generate a C-language flowgraph (DEVELOPMENT) get - get a version of an SCCS file (DEVELOPMENT) chgrp - change the file group ownership getopts - parse utility options chmod - change the file modes grep - search a file for a pattern chown - change the file ownership hash - remember or report utility locations cksum - write file checksums and sizes head - copy the first part of files cmp - compare two files iconv - codeset conversion command - execute a simple command id - return
    [Show full text]
  • Beej's Guide to Unix IPC
    Beej's Guide to Unix IPC Brian “Beej Jorgensen” Hall [email protected] Version 1.1.2 December 15, 2010 Copyright © 2010 Brian “Beej Jorgensen” Hall This guide is written in XML using the vim editor on a Slackware Linux box loaded with GNU tools. The cover “art” and diagrams are produced with Inkscape. The XML is converted into HTML and XSL-FO by custom Python scripts. The XSL-FO output is then munged by Apache FOP to produce PDF documents, using Liberation fonts. The toolchain is composed of 100% Free and Open Source Software. Unless otherwise mutually agreed by the parties in writing, the author offers the work as-is and makes no representations or warranties of any kind concerning the work, express, implied, statutory or otherwise, including, without limitation, warranties of title, merchantibility, fitness for a particular purpose, noninfringement, or the absence of latent or other defects, accuracy, or the presence of absence of errors, whether or not discoverable. Except to the extent required by applicable law, in no event will the author be liable to you on any legal theory for any special, incidental, consequential, punitive or exemplary damages arising out of the use of the work, even if the author has been advised of the possibility of such damages. This document is freely distributable under the terms of the Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License. See the Copyright and Distribution section for details. Copyright © 2010 Brian “Beej Jorgensen” Hall Contents 1. Intro......................................................................................................................................................... 1 1.1. Audience 1 1.2. Platform and Compiler 1 1.3.
    [Show full text]
  • IPCRMS Background Information
    WORLD INTELLECTUAL PROPERTY ORGANIZATION SPECIAL UNION FOR THE INTERNATIONAL PATENT CLASSIFICATION (IPC UNION) IPCRMS Background Information Date By Version Status Modification May 9, 2014 IPCRMS PM 0.1 Draft From PID May 15, 2014 WIPO 1.0 Revised From IPCRMS evaluation team Table of Contents 2.1. Terms Definitions & Acronyms ............................................................................. 2 2.2. Background ................................................................................................................ 3 2.3. Project Objectives ...................................................................................................... 4 2.4. Desired Outcomes ...................................................................................................... 4 2.5. Scope .......................................................................................................................... 4 2.6. Exclusion ................................................................................................................ 5 2.7. Constraints .............................................................................................................. 5 2.8. Assumptions ........................................................................................................... 5 2.9. User(s) and any other known interested parties ..................................................... 6 2.10. Interfaces ................................................................................................................ 6 2.10.1.
    [Show full text]
  • Unix Shared Memory
    Unix Shared Memory 1 What is Shared Memory? The parent and child processes are run in separate address spaces. A shared memory segment is a piece of memory that can be allocated and attached to an address space. Thus, processes that have this memory segment attached will have access to it. But, race conditions can occur! 2 Procedure for Using Shared Memory Find a key. Unix uses this key for identifying shared memory segments. Use shmget() to allocate a shared memory. Use shmat() to attach a shared memory to an address space. Use shmdt() to detach a shared memory from an address space. Use shmctl() to deallocate a shared memory. 3 Keys: 1/2 To use shared memory, include the following: #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> A key is a value of type key_t. There are three ways to generate a key: Do it yourself Use function ftok() Ask the system to provide a private key. 4 Keys: 2/2 Do it yourself: use key_t SomeKey; SomeKey = 1234; Use ftok() to generate one for you: key_t = ftok(char *path, int ID); path is a path name (e.g., “./”) ID is an integer (e.g., ‘a’) Function ftok() returns a key of type key_t: SomeKey = ftok(“./”, ‘x’); Keys are global entities. If other processes know your key, they can access your shared memory. Ask the system to provide a private key using IPC_PRIVATE. 5 Asking for a Shared Memory: 1/4 Include the following: #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> Use shmget() to request a shared memory: shm_id = shmget( key_t key, /* identity key */ int size, /* memory size */ int flag); /* creation or use */ shmget()returns a shared memory ID.
    [Show full text]
  • IPC Revision Manadgement (IPCRM) Project
    IPC Revision Management (IPCRM) Project 48th session of the IPC Committee of Experts Geneva February 25, 2016 Patrick Fiévet Head, IT Systems Section International Classifications and Standards Division Agenda Project Status IPC Revision Management IPCRMS Impact on IPC Master files and by products IPC Revision Management project (IPCRM) status: closed IPC Revision Management project highlights: Initiated mid 2012, the project was largely outsourced through two contractors Business Continuity Management considered Functionality delivered according to approved specification RIPCIS was turned off on November 30, 2015 The IPCRM Project launched in 2012 was closed at the end of 2015 IPC Revision Management project outcome IPC Revision Management Solution (IPCRMS) highlights: “Solution”: Managed Application as a Service i.e. outsourced software, data quality levels, infrastructure hosting, helpdesk, maintenance and support services except WIPO authentication and identity management Solution governance, according to Service Level Agreements (SLA), by WIPO IPC Section staff IPC Revision Management Solution Status: IPCRMS in production since October 13, 2015 Several Change Requests under consideration https://www3.wipo.int/classifications/ipc/ipcrms IPC Revision Management Solution: status Maturity level: 1 (initial) IPCRMS was used by the IB for WG 34 Opened to Offices in read-only mode On-line help, Video tutorial available Ready for Office use in IPC authentic languages and for testing of the National translations support Full impact on IPC
    [Show full text]
  • Mqseries for IRIX Quick Beginnings
    MQSeries for IRIX Quick Beginnings Version 5.1 Edition – February, 2002 Note Before using this information and the product it supports, be sure to read the general information under Appendix D, “Notices”. Second edition (February, 2002) This edition applies to MQSeries for IRIX Version 5.1. and to any subsequent releases and modifications until otherwise indicated in new editions. If you want to make comments regarding this publication please send them to one of the folowing: Mail email Fax Willow Technology, Inc. [email protected] +1.408.296.7700 Publications Dept. 900 Lafayette Street, Suite 604 Santa Clara, CA 95050-4967 U.S.A When you send information to Willow Technology, you grant Willow Technology a nonexclusive right to use or distribute the information in any way it believes appropriate without incurring any obligation to you. © 1998-2002 Copyright Willow Technology, Inc. and its Licensors. All rights reserved. Note to U.S. government Users -- Documentation related to restricted rights -- Use, duplication or disclosure is subject to restrictions set forth in FARS and D-FARS. ii Contents About this manual.........................................................................................................................................1 Who this manual is for?...........................................................................................................................1 What you need to know to understand this manual............................................................................1 Part 1. Guidance
    [Show full text]
  • Shmat() Shmctl() Shared Memory Example
    Shared Memory • Shared Memory allows two or more processes to share a given region of memory – this is the FASTEST form of Systems Programming V IPC because the data does not need to be copied (Shared Memory, Semaphores, between communicating processes • The only trick in using shared memory is synchronizing Concurrency Issues ) access to a given region among multiple processes – if the server/producer process is placing data into a shared Iqbal Mohomed memory region, the client/consumer process shouldn’t try to access it until the server is done CSC 209 – Summer 2004 • Often, semaphores are used to synchronize shared Week 10 memory access shmget() shmat() • shmget() is used to obtain a shared memory identifier • Once a shared memory segment has been created, a process #include<sys/types.h> attaches it to its address space by calling shmat(): #include<sys/ipc.h> • void *shmat(int shmid, void* addr, int flag); #include<sys/shm.h> • shmat() returns a pointer to shared memory segment if OK, -1 on error int shmget(key_t key, int size, int flag); • The recommended technique is to set addr and flag to zero, i.e.: • shmget() returns a shared memory ID if OK, -1 on error • char* buf = (char*)shmat(shmid,0,0); • Key is typically the constant “IPC_PRIVATE”, which lets • The UNIX commands “ipcs” and “ipcrm” are used to list and remove the kernel choose a new key – keys are non-negative shared memory segments on the current machine integer identifier, but unlike fds they are system-wide, • The default action is for a shared memory segment to remain
    [Show full text]