Chapter 11. Tasks, Pipes, and NSTextView

In the last chapter, we built the MathPaper front and back ends. The back end (computational part) was created as a separate program called Evaluator. The front end was created using Cocoa’s powerful multiple-document architecture. In this chapter, we’ll tie the two ends together, learn more about processes, and modify the MathDocument class to display the results of calculations performed by Evaluator.

Processes, Pipes, and Resources

Here’s the big picture of the MathPaper application: one process is responsible for all interaction with the user, while other processes are responsible for performing the actual mathematical calculations. The first process is the MathPaper process itself. The other processes are Evaluator processes that will be created by the MathPaper process using the NSTask class. Communication between the MathPaper and Evaluator processes depends on the NSPipe and NSFileHandle classes. NSTask, NSPipe, and NSFileHandle are Foundation classes that we haven’t used yet; we’ll describe them before using them.

The Unix operating system has always had a rich set of functions dedicated to interprocess communication. Unix uses the fork( ) system function to “spawn” (create) child subprocesses. After a subprocess is spawned, it can change what program it is running by calling the execv( ) system function. One way of communicating with subprocesses is via a pipe , a special kind of file object used by Unix to transmit information ...

Get Building Cocoa Applications: A Step by Step Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.