Caution: This version of this document is no longer maintained. For the latest documentation, see

Preface to the First Edition by Rob Krten

A few years after I started using computers, the very first IBM PC came out. I must have been one of the first people in Ottawa to buy this box, with 16 KB of RAM and no video card, because the salesman wasn't experienced enough to point out that the machine would be totally useless without the video card! Although the box wasn't useful, it did say “IBM” on it (at the time reserved solely for mainframes and the like), so it was impressive on its own. When I finally had enough money to buy the video card, I was able to run BASIC on my parents' TV. To me, this was the height of technology — especially with a 300 baud acoustically coupled modem! So, you can imagine my chagrin, when my friend Paul Trunley called me up and said, “Hey, log in to my computer!” I thought to myself, “Where did he get a VAX from?” since that was the only conceivable machine I knew about that would fit in his parents' house and let you “log in” to. So I called it up. It was a PC running an obscure operating system called “QUNIX,” with a revision number less than 1.00. It let me “log in.” I was hooked!

What has always struck me about the QNX family of operating systems is the small memory footprint, the efficiency, and the sheer elegance of the implementation. I would often entertain (or bore, more likely) dinner guests with stories about all the programs running concurrently on my machine in the basement, as we ate. Those who were knowledgeable about computers would speculate about how huge the disk must be, how I must have near infinite memory, etc. After dinner, I'd drag them downstairs and show them a simple PC with (at the time) 8 MB of RAM and a 70 MB hard disk. This would sometimes impress them. Those who where not impressed would then be shown how much RAM and disk space was still available, and how most of the used disk space was just data I had accumulated over the years.

As time passed, I've had the privilege of working at a number of companies, most of which were involved with some form of QNX development; (from telecoms, to process control, to frame grabber drivers, …), with the single most striking characteristic being the simplicity of the designs and implementation. In my opinion, this is due to the key engineers on the projects having a good understanding of the QNX operating system — if you have a clean, elegant architecture to base your designs on, chances are that your designs will also end up being clean and elegant (unless the problem is really ugly).

In November, 1995, I had the good fortune to work directly for QNX Software Systems (QSS), writing the training material for their two QNX Neutrino courses, and presenting them over the next three years.

It's these past 19 years or so that gave me the inspiration and courage to write the first book, Getting Started with QNX 4 — A Guide for Realtime Programmers, which was published in May, 1998. With this new book on QNX Neutrino, I hope to share some of the concepts and ideas I've learned, so that you can gain a good, solid understanding of how the QNX Neutrino OS works, and how you can use it to your advantage. Hopefully, as you read the book, light bulbs will turn on in your head, making you say “Aha! That's why they did it this way!”

A little history

QSS, the company that created the QNX operating system, was founded in 1980 by Dan Dodge and Gordon Bell (both graduates of the University of Waterloo in Ontario, Canada). Initially, the company was called Quantum Software Systems Limited, and the product was called “QUNIX” (“Quantum UNIX”). After a polite letter from AT&T's lawyers (who owned the “UNIX” trademark at the time), the product's name changed to “QNX.” Some time after that, the company's name itself changed to “QNX Software Systems” — in those days, everyone and their dog seemed to have a company called “Quantum” something or other.

The first commercially successful product was simply called “QNX” and ran on 8088 processors. Then, “QNX 2” (QNX version 2) came out in the early 1980s. It's still running in many mission-critical systems to this day. Around 1991, a new operating system, “QNX 4,” was introduced, with enhanced 32-bit operations and POSIX support. In 1995, the latest member of the QNX family, QNX Neutrino, was introduced. On September 26th, 2000, the QNX Realtime Platform (consisting of the QNX Neutrino operating system, Photon windowing system, development tools and compilers, etc.) was released for free for noncommercial purposes. As of this second printing (July 2001) there have been over 1 million downloads! (Go to to get your free copy.)

Who this book is for

This book is suitable for anyone wishing to gain a good fundamental understanding of the key features of the QNX Neutrino OS and how it works. Readers with a modest computer background should still get a lot out of the book (although the discussion in each chapter gets more and more technical as the chapter progresses). Even diehard hackers should find some interesting twists, especially with the two fundamental features of QNX Neutrino, the message-passing nature of the operating system and the way device drivers are structured.

I've tried to explain things in an easy-to-read “conversational” style, anticipating some of the common questions that come up and answering them with examples and diagrams. Because a complete understanding of the C language isn't required, but is definitely an asset, there are quite a few code samples sprinkled throughout.

What's in this book?

This book introduces you to what the QNX Neutrino operating system is and how it functions. It contains chapters covering process states, threads, scheduling algorithms, message passing, operating system modularity, and so on. If you've never used QNX Neutrino before, but are familiar with realtime operating systems, then you'll want to pay particular attention to the chapters on message passing and resource managers, since these are concepts fundamental to QNX Neutrino.

Processes and Threads

An introduction to processes and threads in QNX Neutrino, realtime, scheduling, and prioritization. You'll learn about scheduling states and QNX Neutrino's scheduling algorithms, as well as the functions you use to control scheduling, create processes and threads, and modify processes and threads that are already running. You'll see how QNX Neutrino implements SMP (Symmetrical Multi-Processing), and the advantages (and pitfalls) that this brings.

“Scheduling and the real world” discusses how threads are scheduled on a running system, and what sorts of things can cause a running thread to be rescheduled.

Message Passing

An introduction to QNX Neutrino's most fundamental feature, message passing. You'll learn what message passing is, how to use it to communicate between threads, and how to pass messages over a network. Priority inversion, the bane of realtime systems everywhere, and other advanced topics are also covered here.

Note: This is one of the most important chapters in this book!

Clocks, Timers, and Getting a Kick Every So Often

Learn all about the system clock and timers, and how to get a timer to send you a message. Lots of practical information here, and code samples galore.


This chapter will teach you how to write interrupt handlers for QNX Neutrino, and how interrupt handlers affect thread scheduling.

Resource Managers

Learn all about QNX Neutrino resource managers (also known variously as “device drivers” and “I/O managers”). You'll need to read and understand the Message Passing chapter before you write your own resource managers. The source for several complete resource managers is included.

Note: Resource managers are another important aspect of every QNX Neutrino-based system.

QNX 4 to QNX Neutrino

This is an invaluable guide for anyone porting their QNX 4 application to QNX Neutrino, or having to maintain code on both platforms. (QNX 4 is QSS's previous-generation operating system, also the subject of my previous book, Getting Started with QNX 4.) Even if you're designing a new application, there may be demand from your customer base to support it on both QNX 4 and QNX Neutrino — if that happens, this section will help you avoid common pitfalls and show you how to write code that's portable to both operating systems.

Calling 911

Where you can turn to when you get stuck, find a bug, or need help with your design.


Contains definitions of the terms used throughout this book.

Other references

In addition to the custom kernel interface, QNX Neutrino implements a wide range of industry standards. This lets you support your favorite publishers when looking for information about standard functions from ANSI, POSIX, TCP/IP, etc.

About Rob Krten

Rob Krten has been doing embedded systems work, mostly on contract, since 1986 and systems-level programming since 1981. During his three year contract at QSS, he designed and presented QSS's courses on “Realtime Programming under the Neutrino Kernel” and “Writing a Resource Manager.” He also wrote the prototype version of QSS's QNX Neutrino Native Networking Manager (Qnet) software, as well as a significant portion of QSS's Building Embedded Systems book.

Both this book and his previous book, Getting Started with QNX 4 — A Guide for Realtime Programmers, have received a Society for Technical Communications (STC; Award of Merit.

Rob maintains a website at


This book would not have been possible without the help and support I received from the following people, who contributed numerous suggestions and comments: Dave Athersych, Luc Bazinet, James Chang, Dan Dodge, Dave Donohoe, Steven Dufresne, Thomas Fletcher, David Gibbs, Marie Godfrey, Bob Hubbard, Mike Hunter, Pradeep Kathail, Steve Marsh, Danny N. Prairie, and Andrew Vernon. (Apologies in advance if I've missed anyone.)

I'd like to particularly thank Brian Stecher, who patiently reviewed at least three complete drafts of this book in detail, and Peter van der Veen, who spent many nights at my place (granted, I did bribe him with beer and pizza), giving me insight into the detailed operations of QNX Neutrino's resource managers.

Thanks to Kim Fraser for once again providing the cover artwork.

Additionally, my thanks goes out to John Ostrander for his excellent grammatical suggestions and detailed proof-reading of of the book :-)

And of course, a special thank-you goes to my editor, Chris Herborth, for finding the time to edit this book, help out with the sometimes obscure SGML/LaTeX tools, etc., all while doing dozens of other things at the same time! [I told you to remind me not to do that again! – chrish]

I'd also like to gratefully acknowledge the patience and understanding of my wife, Christine, for putting up with me while I crawled off into the basement and ignored her for hours on end!