文件名称:193_4ECH.PDF
文件大小:504KB
文件格式:PDF
更新时间:2022-09-06 18:03:43
interprocess communication operating 193_4ECH
In Depth In this chapter, I’m going to take a look at the support Perl offers for interprocess communication (IPC). As far as an operating system is concerned, a process is a running job that has its own execution resources, including share of CPU time. Your process can start or interact with other processes in Perl in plenty of ways. For example, you might want to send a large array-crunching task to a child process, which will signal the main process—that is, the parent process—when it’s done. Handling Interprocess Communication in Perl The support for IPC in Perl ranges over a considerable area, and because it’s an operating system topic, it’s operating system dependent. At its most basic, IPC is as simple as using backticks to execute a system command. When you use backticks, the operating system starts a new process and executes your com- mand. You can also use the exec and system functions to run other programs. However, things start diverging rapidly by operating system from this point on. In Unix, you can use the Perl function fork to start a new process and communi- cate with it after setting up a pipe (a pipe works like a pair of connected file handles) with the pipe function. In fact, you can even use the open function to do the same. You can also send signals between processes and handle the signals that are sent to you. In MS-DOS, the situation is different; fork and other IPC functions are not imple- mented. However, when it is running under Windows, the MS-DOS port of Perl can use Object Linking and Embedding (OLE) automation—also called using code components and code clients—to send data between processes. Besides the Unix support for IPC, then, you’ll also see how to use OLE automation to communicate between Perl and Windows processes such as Microsoft Excel. In this chapter, I’ll also write a code component in Microsoft Visual Basic that you can connect to from Perl scripts, calling the component’s methods and using its properties. In fact, that code component will even be able to display windows, letting you use OLE automation to do what you can’t usually do with Perl in MS-DOS—that is, get graphical. (See Chapter 15 for details on the connection between Perl and the Tk toolkit; that chapter is all about using Tk to display windows, buttons, and more.) NOTE: In Perl v5.6.1, you can use multiple threads, but you need a custom build of Perl. 193_4eC01.P65.fp 8/30/01, 3:13 PM 2 e3 In Depth e1.Built-In Functions: Interprocess Communication You’ll also find more IPC material in one other place in this book, Chapter 20, on the Internet and socket programming. Most people think of sockets as an Internet phenomenon that you use to connect to other machines across the Internet, but in fact, you can use sockets to connect processes on the same machine. And, that’s it. It’s time to turn to the Immediate Solutions now