Interprocess Communication

Total Page:16

File Type:pdf, Size:1020Kb

Interprocess Communication BS1 WS19/20 – topic-based slides Interprocess Communication Pipes (UNIX) • Sockets (UNIX) • Shared Memory (UNIX) • Anonymous Pipes (Windows) • Named Pipes (Windows) • Mailslots (Windows) • Windows vs. UNIX • 2 Inter-Process Communication (IPC) ● Process resources are isolated by the operating system ● IPC requires exceptions to the isolation ● Provided as kernel primitives ● Naïve Idea: Channel with Input & Output ends – “Pipe” Operating Systems 21 UNIX – Pipes ● Unidirectional, unstructured communication channel ● Reading and Writing ends are file-like ● API: read / write ● Backed by a kernel buffer ● read call blocks while the buffer is empty ● write call blocks while the buffer is full ● Indicated in shell programming by the pipe symbol (‘|’) ● Used to chain processes input and output – `ls | less’ Operating Systems 22 UNIX – Pipes ● pipe() creates a set of two file int fd[2]; descriptors ● File descriptors are inherited // fd[0] is for reading by child processes after fork() // fd[1] is for writing ● Example: write a program pipe(fd); that starts two given programs in child processes and connects them in a pipe Operating Systems 23 UNIX – Named Pipes (FIFOs) ● FIFOs are pipes that are represented in the file system ● Need to be open()’ed to produce a file descriptor ● Otherwise behave similarly ● Persist outside of a process scope mknod("myfifo", S_IFIFO | 0644 , 0); mkfifo [OPTION]... NAME... ● No concept of “connections” Operating Systems 24 UNIX – Sockets ● Network Sockets ● represented by network address (IP, Port) ● Local Domain Sockets ● represented by path in file system ● Connection-oriented (TCP) (bind / listen / accept) ● Bidirectional, indicative of a client / server architecture ● Bound to a listening process Operating Systems 25 UNIX – Shared Memory ● Processes can share memory explicitly int shm_open(const char *name, int oflag, mode_t mode) ● Shared memory segments are a named resource ● Represented within process resources through file descriptor ● Can be mapped to process address space using mmap ● Access has to be synchronized (critical sections) Operating Systems 26 Windows – Anonymous Pipes Half-duplex character-based IPC BOOL CreatePipe( PHANDLE phRead, ● cbPipe: pipe buffer size in bytes; PHANDLE phWrite, zero == default LPSECURITY_ATTRIBUTES lpsa, DWORD cbPipe ) ● Read operation on empty pipe will block ● Write operation to a full pipe will block main ● Anonymous pipes are oneway prog1 pipe prog2 ● Example: $ date | more Operating Systems 27 I/O Redirection using an Anonymous Pipe /* Create default size anonymous pipe, handles are inheritable. */ if (!CreatePipe (&hReadPipe, &hWritePipe, &PipeSA, 0)) { fprintf(stderr, “Anon pipe create failed\n”); exit(1); } /* Set output handle to pipe handle, create first processes. */ StartInfoCh1.hStdInput = GetStdHandle (STD_INPUT_HANDLE); StartInfoCh1.hStdError = GetStdHandle (STD_ERROR_HANDLE); StartInfoCh1.hStdOutput = hWritePipe; StartInfoCh1.dwFlags = STARTF_USESTDHANDLES; if (!CreateProcess (NULL, (LPTSTR)Command1, NULL, NULL, TRUE, 0, NULL, NULL, &StartInfoCh1, &ProcInfo1)) { fprintf(stderr, “CreateProc1 failed\n”); exit(2); } CloseHandle (hWritePipe); Operating Systems 28 I/O Redirection using an Anonymous Pipe /* Repeat (symmetrically) for the second process. */ StartInfoCh2.hStdInput = hReadPipe; StartInfoCh2.hStdError = GetStdHandle (STD_ERROR_HANDLE); StartInfoCh2.hStdOutput = GetStdHandle (STD_OUTPUT_HANDLE); StartInfoCh2.dwFlags = STARTF_USESTDHANDLES; if (!CreateProcess (NULL, (LPTSTR)targv, NULL, NULL, TRUE, 0, NULL, NULL, &StartInfoCh2, &ProcInfo2)) { fprintf(stderr, “CreateProc2 failed\n”); exit(3); } CloseHandle (hReadPipe); /* Wait for both processes to complete. */ WaitForSingleObject (ProcInfo1.hProcess, INFINITE); WaitForSingleObject (ProcInfo2.hProcess, INFINITE); CloseHandle (ProcInfo1.hThread); CloseHandle (ProcInfo1.hProcess); CloseHandle (ProcInfo2.hThread); CloseHandle (ProcInfo2.hProcess); return 0; Operating Systems 29 Windows – Named Pipes ● Message oriented ● Reading process can read varying-length messages precisely as sent by the writing process ● Bi-directional ● Two processes can exchange messages over the same pipe ● Multiple, independent instances of a named pipe: ● Several clients can communicate with a single server using the same instance ● Server can respond to client using the same instance ● Pipe can be accessed over the network ● location transparency ● Convenience and connection functions Operating Systems 30 Using Windows Named Pipes HANDLE CreateNamedPipe (LPCTSTR lpszPipeName, DWORD fdwOpenMode, DWORD fdwPipMode DWORD nMaxInstances, DWORD cbOutBuf, DWORD cbInBuf, DWORD dwTimeOut, LPSECURITY_ATTRIBUTES lpsa ); ● lpszPipeName: \\.\pipe\[path]pipename ● Not possible to create a pipe on remote machine (. – local machine) ● FdwOpenMode: PIPE_ACCESS_DUPLEX, PIPE_ACCESS_INBOUND, PIPE_ACCESS_OUTBOUND ● fdwPipeMode: ● PIPE_TYPE_BYTE or PIPE_TYPE_MESSAGE ● PIPE_READMODE_BYTE or PIPE_READMODE_MESSAGE ● PIPE_WAIT or PIPE_NOWAIT (will ReadFile block?) Operating Systems 31 Using Windows Named Pipes ● nMaxInstances: ● Number of instances, ● PIPE_UNLIMITED_INSTANCES: OS choice based on resources ● dwTimeOut ● Default time-out period (in msec) for WaitNamedPipe() ● First CreateNamedPipe creates named pipe ● Closing handle to last instance deletes named pipe ● Polling a pipe: ● Nondestructive – is there a message waiting for ReadFile BOOL PeekNamedPipe (HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer, LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage);Operating Systems 32 Using Windows Named Pipes ● CreateFile with named pipe name: ● Local: \\.\pipe\[path]pipename ● Remote: \\servername\pipe\[path]pipename ● Status Functions: ● GetNamedPipeHandleState(...) ● SetNamedPipeHandleState(...) ● GetNamedPipeInfo(...) Operating Systems 33 Convenience Functions ● WriteFile / ReadFile sequence: BOOL TransactNamedPipe( HANDLE hNamedPipe, LPVOID lpvWriteBuf, DWORD cbWriteBuf, LPVOID lpvReadBuf, DWORD cbReadBuf, LPDOWRD lpcbRead, LPOVERLAPPED lpa); ● CreateFile / WriteFile / ReadFile / CloseHandle: ● dwTimeOut: NMPWAIT_NOWAIT, NMPWAIT_WIAT_FOREVER, NMPWAIT_USE_DEFAULT_WAIT BOOL CallNamedPipe( LPCTSTR lpszPipeName, LPVOID lpvWriteBuf, DWORD cbWriteBuf, LPVOID lpvReadBuf, DWORD cbReadBuf, LPDWORD lpcbRead,Operating SystemsDWORD dwTimeOut); 34 Server: eliminate the polling loop BOOL ConnectNamedPipe (HANDLE hNamedPipe, LPOVERLAPPED lpo ); ● lpo == NULL: ● Call will return as soon as there is a client connection ● Returns false if client connected between CreateNamed Pipe call and ConnectNamedPipe() ● Use DisconnectNamedPipe to free the handle for connection from another client ● WaitNamedPipe(): ● Client may wait for server‘s ConnectNamedPipe() ● Security rights for named pipes: ● GENERIC_READ, GENERIC_WRITE, SYNCHRONIZE Operating Systems 35 Client Example using a Named Pipe WaitNamedPipe (ServerPipeName, NMPWAIT_WAIT_FOREVER); hNamedPipe = CreateFile (ServerPipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hNamedPipe == INVALID_HANDLE_VALUE) { fptinf(stderr, “Failure to locate server.\n"); exit(3); } /* Write the request. */ WriteFile (hNamedPipe, &Request, MAX_RQRS_LEN, &nWrite, NULL); /* Read each response and send it to std out. */ while (ReadFile (hNamedPipe, Response.Record, MAX_RQRS_LEN, &nRead, NULL)) printf ("%s", Response.Record); CloseHandle (hNamedPipe); return 0; Operating Systems 36 Server Example Using a Named Pipe hNamedPipe = CreateNamedPipe (SERVER_PIPE, PIPE_ACCESS_DUPLEX, PIPE_READMODE_MESSAGE | PIPE_TYPE_MESSAGE | PIPE_WAIT, 1, 0, 0, CS_TIMEOUT, pNPSA); while (!Done) { printf ("Server is awaiting next request.\n"); if (!ConnectNamedPipe (hNamedPipe, NULL) || !ReadFile (hNamedPipe, &Request, RQ_SIZE, &nXfer, NULL)) { fprintf(stderr, “Connect or Read Named Pipe error\n”); exit(4); } printf(“Request is: %s\n", Request.Record); /* Send the file, one line at a time, to the client. */ fp = fopen (File, "r"); while ((fgets (Response.Record, MAX_RQRS_LEN, fp) != NULL)) WriteFile (hNamedPipe, &Response.Record, (strlen(Response.Record) + 1) * TSIZE, &nXfer, NULL); fclose (fp); DisconnectNamedPipe (hNamedPipe); } /* End of server operation. */ Operating Systems 37 UNIX vs. Windows ● UNIX FIFOs are similar to Windows Named Pipe ● FIFOs are half-duplex ● FIFOs are limited to a single machine ● FIFOs are byte-oriented; fixed-size records in client/server applications ● Individual read/writes are atomic; serialized by the kernel ● A server using FIFOs must use a separate FIFO for each client‘s response, although all clients can send requests via a single, well known FIFO ● Mkfifo() is the UNIX counterpart to CreateNamedPipe() ● Use sockets for networked client/server scenarios Operating Systems 38 Windows – Mailslots ● Broadcast mechanism: ● One-directional; unreliable ● Mutliple writers/multiple readers (frequently: one-to-many comm.) ● Can be located over a network domain ● Message lengths are limited (w2k: < 426 byte) ● Operations on the mailslot: ● Each reader (server) creates mailslot with CreateMailslot() ● Write-only client opens mailslot with CreateFile() and uses WriteFile() – open will fail if there are no waiting readers ● Client‘s message can be read by all servers (readers) ● Client lookup: \\*\mailslot\mailslotname ● Client will connect to every server in network domain ● Mailslots bear some nasty implementation details; they are almost never used Operating Systems 39 Locate a server via mailslot Mailslot Servers Mailslot Client App client 0 Message is sent periodically
Recommended publications
  • Inter-Process Communication, Analysis, Guidelines and Its Impact on Computer Security
    The 7th International Conference for Informatics and Information Technology (CIIT 2010) INTER-PROCESS COMMUNICATION, ANALYSIS, GUIDELINES AND ITS IMPACT ON COMPUTER SECURITY Zoran Spasov Ph.D. Ana Madevska Bogdanova T-Mobile Macedonia Institute of Informatics, FNSM Skopje, Macedonia Skopje, Macedonia ABSTRACT Finally the conclusion will offer a summary of the available programming techniques and implementations for the In this paper we look at the inter-process communication Windows platforms. We will note the security risks and the (IPC) also known as inter-thread or inter-application best practices to avoid them. communication from other knowledge sources. We will look and analyze the different types of IPC in the Microsoft II. INTER -PROCESS COMMUNICATION (IPC) Windows operating system, their implementation and the usefulness of this kind of approach in the terms of Inter-Process Communication (IPC) stands for many communication between processes. Only local techniques for the exchange of data among threads in one or implementation of the IPC will be addressed in this paper. more processes - one-directional or two-directional. Processes Special emphasis will be given to the system mechanisms that may be running locally or on many different computers are involved with the creation, management, and use of connected by a network. We can divide the IPC techniques named pipes and sockets. into groups of methods, grouped by their way of This paper will discuss some of the IPC options and communication: message passing, synchronization, shared techniques that are available to Microsoft Windows memory and remote procedure calls (RPC). We should programmers. We will make a comparison between Microsoft carefully choose the IPC method depending on data load that remoting and Microsoft message queues (pros and cons).
    [Show full text]
  • An Introduction to Linux IPC
    An introduction to Linux IPC Michael Kerrisk © 2013 linux.conf.au 2013 http://man7.org/ Canberra, Australia [email protected] 2013-01-30 http://lwn.net/ [email protected] man7 .org 1 Goal ● Limited time! ● Get a flavor of main IPC methods man7 .org 2 Me ● Programming on UNIX & Linux since 1987 ● Linux man-pages maintainer ● http://www.kernel.org/doc/man-pages/ ● Kernel + glibc API ● Author of: Further info: http://man7.org/tlpi/ man7 .org 3 You ● Can read a bit of C ● Have a passing familiarity with common syscalls ● fork(), open(), read(), write() man7 .org 4 There’s a lot of IPC ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memory attach ● Pseudoterminals ● proc_vm_readv() / proc_vm_writev() ● Sockets ● Signals ● Stream vs Datagram (vs Seq. packet) ● Standard, Realtime ● UNIX vs Internet domain ● Eventfd ● POSIX message queues ● Futexes ● POSIX shared memory ● Record locks ● ● POSIX semaphores File locks ● ● Named, Unnamed Mutexes ● System V message queues ● Condition variables ● System V shared memory ● Barriers ● ● System V semaphores Read-write locks man7 .org 5 It helps to classify ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memory attach ● Pseudoterminals ● proc_vm_readv() / proc_vm_writev() ● Sockets ● Signals ● Stream vs Datagram (vs Seq. packet) ● Standard, Realtime ● UNIX vs Internet domain ● Eventfd ● POSIX message queues ● Futexes ● POSIX shared memory ● Record locks ● ● POSIX semaphores File locks ● ● Named, Unnamed Mutexes ● System V message queues ● Condition variables ● System V shared memory ● Barriers ● ● System V semaphores Read-write locks man7 .org 6 It helps to classify ● Pipes ● Shared memory mappings ● FIFOs ● File vs Anonymous ● Cross-memoryn attach ● Pseudoterminals tio a ● proc_vm_readv() / proc_vm_writev() ● Sockets ic n ● Signals ● Stream vs Datagram (vs uSeq.
    [Show full text]
  • CS 5600 Computer Systems
    CS 5600 Computer Systems Lecture 4: Programs, Processes, and Threads • Programs • Processes • Context Switching • Protected Mode Execution • Inter-process Communication • Threads 2 Running Dynamic Code • One basic function of an OS is to execute and manage code dynamically, e.g.: – A command issued at a command line terminal – An icon double clicked from the desktop – Jobs/tasks run as part of a batch system (MapReduce) • A process is the basic unit of a program in execution 3 Programs and Processes Process The running instantiation of a program, stored in RAM Program An executable file in long-term One-to-many storage relationship between program and processes 4 How to Run a Program? • When you double-click on an .exe, how does the OS turn the file on disk into a process? • What information must the .exe file contain in order to run as a program? 5 Program Formats • Programs obey specific file formats – CP/M and DOS: COM executables (*.com) – DOS: MZ executables (*.exe) • Named after Mark Zbikowski, a DOS developer – Windows Portable Executable (PE, PE32+) (*.exe) • Modified version of Unix COFF executable format • PE files start with an MZ header. – Mac OSX: Mach object file format (Mach-O) – Unix/Linux: Executable and Linkable Format (ELF) • designed to be flexible and extensible • all you need to know to load and start execution regardless of architecture 6 ABI - Application Binary Interface • interface between 2 programs at the binary (machine code) level – informally, similar to API but on bits and bytes • Calling conventions –
    [Show full text]
  • IPC: Mmap and Pipes
    Interprocess Communication: Memory mapped files and pipes CS 241 April 4, 2014 University of Illinois 1 Shared Memory Private Private address OS address address space space space Shared Process A segment Process B Processes request the segment OS maintains the segment Processes can attach/detach the segment 2 Shared Memory Private Private Private address address space OS address address space space space Shared Process A segment Process B Can mark segment for deletion on last detach 3 Shared Memory example /* make the key: */ if ((key = ftok(”shmdemo.c", 'R')) == -1) { perror("ftok"); exit(1); } /* connect to (and possibly create) the segment: */ if ((shmid = shmget(key, SHM_SIZE, 0644 | IPC_CREAT)) == -1) { perror("shmget"); exit(1); } /* attach to the segment to get a pointer to it: */ data = shmat(shmid, (void *)0, 0); if (data == (char *)(-1)) { perror("shmat"); exit(1); } 4 Shared Memory example /* read or modify the segment, based on the command line: */ if (argc == 2) { printf("writing to segment: \"%s\"\n", argv[1]); strncpy(data, argv[1], SHM_SIZE); } else printf("segment contains: \"%s\"\n", data); /* detach from the segment: */ if (shmdt(data) == -1) { perror("shmdt"); exit(1); } return 0; } Run demo 5 Memory Mapped Files Memory-mapped file I/O • Map a disk block to a page in memory • Allows file I/O to be treated as routine memory access Use • File is initially read using demand paging ! i.e., loaded from disk to memory only at the moment it’s needed • When needed, a page-sized portion of the file is read from the file system
    [Show full text]
  • Interprocess Communication
    06 0430 CH05 5/22/01 10:22 AM Page 95 5 Interprocess Communication CHAPTER 3,“PROCESSES,” DISCUSSED THE CREATION OF PROCESSES and showed how one process can obtain the exit status of a child process.That’s the simplest form of communication between two processes, but it’s by no means the most powerful.The mechanisms of Chapter 3 don’t provide any way for the parent to communicate with the child except via command-line arguments and environment variables, nor any way for the child to communicate with the parent except via the child’s exit status. None of these mechanisms provides any means for communicating with the child process while it is actually running, nor do these mechanisms allow communication with a process outside the parent-child relationship. This chapter describes means for interprocess communication that circumvent these limitations.We will present various ways for communicating between parents and chil- dren, between “unrelated” processes, and even between processes on different machines. Interprocess communication (IPC) is the transfer of data among processes. For example, a Web browser may request a Web page from a Web server, which then sends HTML data.This transfer of data usually uses sockets in a telephone-like connection. In another example, you may want to print the filenames in a directory using a command such as ls | lpr.The shell creates an ls process and a separate lpr process, connecting 06 0430 CH05 5/22/01 10:22 AM Page 96 96 Chapter 5 Interprocess Communication the two with a pipe, represented by the “|” symbol.A pipe permits one-way commu- nication between two related processes.The ls process writes data into the pipe, and the lpr process reads data from the pipe.
    [Show full text]
  • Interprocess Communications (Pipes)
    Multiple methods for Interprocess Communications Three examples: files, pipes, shared memory. In this figure, Local domain sockets would be conceptually similar to a named pipe. The second method refers to pipes Sources for these slides include: • W. Stevens, Unix Network Programming, Volumes 1 and 2 • M. Mitchell, J. Oldham, A. Samuel, Advanced Linux Programming 1 Interprocess Communication (IPC) ⚫ Linux supports the following IPC mechanisms: – Half duplex pipes – Full duplex pipes –only by using 2 pipes (other unix systems do support FD over a single pipe) – FIFOS (also called named pipes) – SYSV style message queues – SYSV style shared memory – Local Domain (UNIX Domain) sockets – Similar to a socket but modifications to the address/name aspect. (PF_LOCAL rather than PF_INET). – Sockets: Two processes can communicate using localhost. But it’s more efficient to use 2 pipes or local domain sockets. Pipe – used in a shell pipeline ⚫ Example of a pipeline - issue the following in a shell: – who | sort | wc 2 10 110 – The shell program creates three processes, two pipes are used as shown below. – The shell would use the dup2 call to duplicate the read end of each pipe to standard input and the write end to standard output. ⚫ int fd[2]; ⚫ pid_t pid; ⚫ pipe(fd); ⚫ pid = fork(); ⚫ If(pid == 0) { – dup2(fd[0], STDIN_FILENO); – exec(whatever); ⚫ } ⚫ The use of dup2 by a shell allows a program or filter to simply operate on data arriving through standard in….and sends output to standard out. It does not need to know the pipe descriptors involved…. 3 – Note – modified the pipeline- the figure assumes lp instead of wc .
    [Show full text]
  • Half-Process: a Process Partially Sharing Its Address Space with Other Processes
    Electronic Preprint for Journal of Information Processing Vol.20 No.1 Regular Paper Half-process: A Process Partially Sharing Its Address Space with Other Processes Kentaro Hara1,a) Kenjiro Taura1 Received: March 31, 2011, Accepted: September 12, 2011 Abstract: Threads share a single address space with each other. On the other hand, a process has its own address space. Since whether to share or not to share the address space depends on each data structure in the whole program, the choice of “a thread or a process” for the whole program is too much “all-or-nothing.” With this motivation, this paper proposes a half-process, a process partially sharing its address space with other processes. This paper describes the design and the kernel-level implementation of the half-process and discusses the potential applicability of the half-process for multi-thread programming with thread-unsafe libraries, intra-node communications in parallel pro- gramming frameworks and transparent kernel-level thread migration. In particular, the thread migration based on the half-process is the first work that achieves transparent kernel-level thread migration by solving the problem of sharing global variables between threads. Keywords: partitioned global address space, Linux kernel, thread migration, finite element method, reconfiguration, productivity 1. Introduction Threads share a single address space with each other. When one thread issues memory operations such as mmap()/munmap()/mprotect(), all threads can see the ef- fects immediately. When one thread updates a memory address, Fig. 1 The design of a half-process. all threads can see the update immediately. In addition, all programmer can enjoy both advantages of process and thread, threads can access the same data with the same address.
    [Show full text]
  • Interacting Modelica Using a Named Pipe for Hardware-In-The-Loop Simulation
    Interacting Modelica using a Named Pipe for Hardware-in-the-loop Simulation Interacting Modelica using a Named Pipe for Hardware-in-the-loop Simulation Arno Ebner Anton Haumer Dragan Simic Franz Pirker Arsenal Research Giefinggasse 2, 1210 Vienna, Austria phone: +43 50550 6663, fax: +43 50550 6595, e-mail: [email protected] Abstract tion for the system model considering the initial val- ues. The paper presents a concept and an implementation In some cases the user or other applications have to of Modelica simulation interaction using the operat- interact with the simulation, for example to: ing system inter-process communication method of • Start or interrupt the simulation the Named Pipe. The main aim of this presented • Change parameters or variables during the simu- work is to implement a hardware-in-the-loop simula- lation tion (HILS) environment based on Dymola which • Communicate with other applications, for exam- runs on a normal Microsoft Windows Personal Com- ple with another simulation environment puter. • Exchange data with an input/output-card or a pe- An energy storage test bench is connected by an ana- ripheral communication interface logue and digital data input/output card with the Dy- • Build up a hardware-in-the-loop simulation envi- mola simulation computer. With this proposed sys- ronment tem, particularly long-time simulations with sample rates up to 30 Hz can be executed very cost effective. Hardware-in-the-loop (HIL) is the integration of real Typical applications are simulations of drive cycles components and system models in a common simu- to test energy storage systems in electrified vehicles lation environment [1].
    [Show full text]
  • Linux/Unix Inter-Process Communication
    Mohammad S. Hasan Faculty of Computing, Engineering & Technology Linux/Unix inter-process communication Mohammad S. Hasan Staffordshire University, UK Linux/Unix inter-process communication Slide 1 Mohammad S. Hasan Faculty of Computing, Engineering & Technology Lecture Outline Inter-process communication methods in Linux/Unix Files Pipes FIFOs Signals Sockets System V IPC - semaphores, messages, shared memory Linux/Unix inter-process communication Slide 2 Mohammad S. Hasan Faculty of Computing, Engineering & Technology Interprocess communication (IPC) There are many interprocess communication mechanisms in UNIX and Linux Each mechanism has its own system calls, advantages and disadvantages Files, pipes, FIFOs, signals, semaphores, messages, shared memory, sockets, streams We will look a number of them Linux/Unix inter-process communication Slide 3 Mohammad S. Hasan Faculty of Computing, Engineering & Technology Interprocess communication (IPC) (Cont.) Linux/Unix inter-process communication Slide 4 Mohammad S. Hasan Faculty of Computing, Engineering & Technology Files These can handle simple IPC but have 2 P1 main problems for serious IPC work: Writer if reader faster than writer, then reader reads EOF, but cannot tell whether it has simply caught up with writer or writer has File …. completed (synchronisation problem) …. …. writer only writes to end of file, thus files EOF can grow very large for long lived processes (disk/memory space problem) P2 Reader Linux/Unix inter-process communication Slide 5 Mohammad S. Hasan Faculty of Computing, Engineering & Technology Pipes You should already be familiar with pipe from practical exercises e.g. who | sort This sets up a one directional pipeline that takes the output from ‘who’ and gives it as input to ‘sort’ Linux/Unix inter-process communication Slide 6 Mohammad S.
    [Show full text]
  • System Calls & Signals
    CS345 OPERATING SYSTEMS System calls & Signals Panagiotis Papadopoulos [email protected] 1 SYSTEM CALL When a program invokes a system call, it is interrupted and the system switches to Kernel space. The Kernel then saves the process execution context (so that it can resume the program later) and determines what is being requested. The Kernel carefully checks that the request is valid and that the process invoking the system call has enough privilege. For instance some system calls can only be called by a user with superuser privilege (often referred to as root). If everything is good, the Kernel processes the request in Kernel Mode and can access the device drivers in charge of controlling the hardware (e.g. reading a character inputted from the keyboard). The Kernel can read and modify the data of the calling process as it has access to memory in User Space (e.g. it can copy the keyboard character into a buffer that the calling process has access to) When the Kernel is done processing the request, it restores the process execution context that was saved when the system call was invoked, and control returns to the calling program which continues executing. 2 SYSTEM CALLS FORK() 3 THE FORK() SYSTEM CALL (1/2) • A process calling fork()spawns a child process. • The child is almost an identical clone of the parent: • Program Text (segment .text) • Stack (ss) • PCB (eg. registers) • Data (segment .data) #include <sys/types.h> #include <unistd.h> pid_t fork(void); 4 THE FORK() SYSTEM CALL (2/2) • The fork()is one of the those system calls, which is called once, but returns twice! Consider a piece of program • After fork()both the parent and the child are ..
    [Show full text]
  • SMB Analysis
    NAP-3 Microsoft SMB Troubleshooting Rolf Leutert, Leutert NetServices, Switzerland © Leutert NetServices 2013 www.wireshark.ch Server Message Block (SMB) Protokoll SMB History Server Message Block (SMB) is Microsoft's client-server protocol and is most commonly used in networked environments where Windows® operating systems are in place. Invented by IBM in 1983, SMB has become Microsoft’s core protocol for shared services like files, printers etc. Initially SMB was running on top of non routable NetBIOS/NetBEUI API and was designed to work in small to medium size workgroups. 1996 Microsoft renamed SMB to Common Internet File System (CIFS) and added more features like larger file sizes, Windows RPC, the NT domain service and many more. Samba is the open source SMB/CIFS implementation for Unix and Linux systems 2 © Leutert NetServices 2013 www.wireshark.ch Server Message Block (SMB) Protokoll SMB over TCP/UDP/IP SMB over NetBIOS over UDP/TCP SMB / NetBIOS was made routable by running Application over TCP/IP (NBT) using encapsulation over 137/138 139 TCP/UDP-Ports 137–139 .. Port 137 = NetBIOS Name Service (NS) Port 138 = NetBIOS Datagram Service (DGM) Port 139 = NetBIOS Session Service (SS) Data Link Ethernet, WLAN etc. Since Windows 2000, SMB runs, by default, with a thin layer, the NBT's Session Service, on SMB “naked” over TCP top of TCP-Port 445. Application 445 DNS and LLMNR (Link Local Multicast Name . Resolution) is used for name resolution. Port 445 = Microsoft Directory Services (DS) SMB File Sharing, Windows Shares, Data Link Ethernet, WLAN etc. Printer Sharing, Active Directory 3 © Leutert NetServices 2013 www.wireshark.ch Server Message Block (SMB) Protokoll NetBIOS / SMB History NetBIOS Name Service (UDP Port 137) Application • Using NetBIOS names for clients and services.
    [Show full text]
  • Technical Standard IPC Mechanisms For
    Technical Standard IPC Mechanisms for SMB NICAL H S C T A E N T D A R D [This page intentionally left blank] X/Open CAE Specification IPC Mechanisms for SMB X/Open Company Ltd. December 1991, X/Open Company Limited All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior permission of the copyright owners. X/Open CAE Specification IPC Mechanisms for SMB ISBN: 1 872630 28 6 X/Open Document Number: XO/CAE/91/500 Published by X/Open Company Ltd., U.K. Any comments relating to the material contained in this document may be submitted to X/Open at: X/Open Company Limited Apex Plaza Forbury Road Reading Berkshire, RG1 1AX United Kingdom or by Electronic Mail to: [email protected] ii X/Open CAE Specification (1991) Contents Chapter 1 Introduction............................................................................................... 1 Chapter 2 SMB IPC Service Model .................................................................... 3 2.1 Security Overview ...................................................................................... 3 2.2 Naming ......................................................................................................... 4 2.2.1 Named Pipe and Mailslot Names ........................................................ 4 2.2.2 NetBIOS Names ....................................................................................... 4 2.2.3 Messaging
    [Show full text]