26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Threads and processes<br />

In fact, system() actually starts up a shell to handle the command that you want to<br />

perform.<br />

The editor that I’m using to write this book makes use of the system() call. When I’m<br />

editing, I may need to “shell out,” check out some samples, and then come back into<br />

the editor, all <strong>with</strong>out losing my place. In this editor, I may issue the command :!pwd<br />

for example, to display the current working directory. The editor runs this code for the<br />

:!pwd command:<br />

system ("pwd");<br />

Is system() suited for everything under the sun? Of course not, but it’s useful for a lot<br />

of your process-creation requirements.<br />

Starting a process <strong>with</strong> the exec() and spawn() calls<br />

Let’s look at some of the other process-creation functions.<br />

The next process-creation functions we should look at are the exec() and spawn()<br />

families. Before we go into the details, let’s see what the differences are between these<br />

two groups of functions.<br />

The exec() family transforms the current process into another one. What I mean by<br />

that is that when a process issues an exec() function call, that process ceases to run the<br />

current program and begins to run another program. The process ID doesn’t change —<br />

that process changed into another program. What happened to all the threads in the<br />

process? We’ll come back to that when we look at fork().<br />

The spawn() family, on the other hand, doesn’t do that. Calling a member of the<br />

spawn() family creates another process (<strong>with</strong> a new process ID) that corresponds to<br />

the program specified in the function’s arguments.<br />

Let’s look at the different variants of the spawn() and exec() functions. In the table that<br />

follows, you’ll see which ones are POSIX and which aren’t. Of course, for maximum<br />

portability, you’ll want to use only the POSIX functions.<br />

Spawn POSIX? Exec POSIX?<br />

spawn() No<br />

spawnl() No execl() Yes<br />

spawnle() No execle() Yes<br />

spawnlp() No execlp() Yes<br />

spawnlpe() No execlpe() No<br />

spawnp() No<br />

spawnv() No execv() Yes<br />

continued. . .<br />

April 30, 2009 Chapter 1 • Processes and Threads 29

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!