System Startup Programming Topics

Total Page:16

File Type:pdf, Size:1020Kb

System Startup Programming Topics System Startup Programming Topics 2006-10-03 Java and all Java-based trademarks are Apple Computer, Inc. trademarks or registered trademarks of Sun © 2003, 2006 Apple Computer, Inc. Microsystems, Inc. in the U.S. and other All rights reserved. countries. PowerPC and and the PowerPC logo are No part of this publication may be trademarks of International Business reproduced, stored in a retrieval system, or Machines Corporation, used under license transmitted, in any form or by any means, therefrom. mechanical, electronic, photocopying, recording, or otherwise, without prior Simultaneously published in the United written permission of Apple Computer, Inc., States and Canada. with the following exceptions: Any person Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR is hereby authorized to store documentation REPRESENTATION, EITHER EXPRESS OR on a single computer for personal use only IMPLIED, WITH RESPECT TO THIS and to print copies of documentation for DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A personal use provided that the PARTICULAR PURPOSE. AS A RESULT, THIS documentation contains Apple’s copyright DOCUMENT IS PROVIDED “AS IS,” AND YOU, THE READER, ARE ASSUMING THE notice. ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. The Apple logo is a trademark of Apple IN NO EVENT WILL APPLE BE LIABLE FOR Computer, Inc. DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES Use of the “keyboard” Apple logo RESULTING FROM ANY DEFECT OR (Option-Shift-K) for commercial purposes INACCURACY IN THIS DOCUMENT, even if without the prior written consent of Apple advised of the possibility of such damages. may constitute trademark infringement and THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN unfair competition in violation of federal LIEU OF ALL OTHERS, ORAL OR WRITTEN, and state laws. EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any No licenses, express or implied, are granted modification, extension, or addition to this with respect to any of the technology warranty. described in this document. Apple retains Some states do not allow the exclusion or limitation of implied warranties or liability for all intellectual property rights associated incidental or consequential damages, so the with the technology described in this above limitation or exclusion may not apply to you. This warranty gives you specific legal document. This document is intended to rights, and you may also have other rights which assist application developers to develop vary from state to state. applications only for Apple-labeled or Apple-licensed computers. Every effort has been made to ensure that the information in this document is accurate. Apple is not responsible for typographical errors. Apple Computer, Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 Apple, the Apple logo, Carbon, Cocoa, iTunes, Mac, Mac OS, Macintosh, Pages, and Xcode are trademarks of Apple Computer, Inc., registered in the United States and other countries. Finder is a trademark of Apple Computer, Inc. Intel and Intel Core are registered trademarks of Intel Corportation or its subsidiaries in the United States and other countries. Contents Introduction to System Startup Programming Topics 7 Organization of This Document 7 The Boot Process 9 BootROM 9 BootX, boot.efi, and System Initialization 10 Authenticating Users 11 Configuring User Sessions 11 Logout Responsibilities 12 Application Responsibilities 13 Terminating Processes 14 Identifying the Scope of Processes 15 The Shutdown Process 15 Daemons 17 Communicating With Daemons 17 Viewing the Currently Running Daemons 18 Running a Process on a Schedule 19 Timed Jobs Using Periodic Jobs 19 Timed Jobs Using cron 20 Timed Jobs Using launchd 20 Timed Jobs Using at 21 Guidelines for Creating and Launching Daemons 23 When Is a Custom Daemon Appropriate? 23 Launching Custom Daemons On Demand 24 Launching Daemons From Startup Items 24 Creating Launch-On-Demand Daemons and Agents 25 The Launch-on-Demand Process 25 Daemon Requirements 26 Required Behaviors 26 Recommended Behaviors 27 Creating a Launchd Property List File 28 3 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. Deciding When to Shut Down 29 Special Dependencies 29 For More Information 31 Creating a Startup Item 33 Anatomy of a Startup Item 33 Creating the Startup Item Executable 34 Specifying the Startup Item Properties 35 Managing Startup Items 37 Displaying and Localizing a Startup Message 37 Startup Item Permissions 38 Logging Errors and Warnings 41 Log Levels and Log Files 41 Logging Errors Using the syslog API 42 Logging Errors Using the asl API 44 Customizing Login and Logout 45 Login Items 45 Adding Login and Logout Items with Apple Events 45 Adding Login and Logout Items with CFPreferences 45 Adding Login and Logout Items Manually 46 Loginwindow Scripts 47 Installing Scripts Using Defaults 47 Installing Scripts Using Loginwindow Hooks 48 Bootstrap Daemons 49 Launchd User Agents 49 Document Revision History 51 Index 53 4 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. Figures and Tables Daemons 17 Figure 1 Processes shown in Activity Monitor 19 Creating Launch-On-Demand Daemons and Agents 25 Table 1 Required and recommended property list keys 28 Creating a Startup Item 33 Table 1 StartupParameters.plist key-value pairs 35 Customizing Login and Logout 45 Table 1 loginwindow parameters 48 5 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. 6 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. Introduction to System Startup Programming Topics System startup (also known as the boot process) involves a sequence of actions that prepare the computer for use by the user. This sequence includes a number of different tasks, including initializing hardware, starting system daemons, and displaying the login window. After a user logs in, the system completes an additional series of actions that sets up the computing environment for that user. This document provides information that developers of daemons and other low-level system services need to write their code and incorporate it into the startup process. It also provides some useful information for system administrators who must manage the startup process on the computers they manage. You should read this document if you are writing or porting software that needs to be launched at boot time or at user login time. You should also read this document if you are interested in the system logging facilities provided by Apple system log (asl) facility. Organization of This Document This programming topic includes the following articles: ■ “The Boot Process” (page 9) describes the overall sequence that occurs when Mac OS X boots, focusing on the places where developers can customize the boot cycle. ■ “Daemons” (page 17) provides background information on daemons in Mac OS X. ■ “Guidelines for Creating and Launching Daemons” (page 23) provides basic guidelines for developers who want to run daemons on Mac OS X. ■ “Creating Launch-On-Demand Daemons” (page 25) provides guidance on how to create a daemon that runs under launchd. ■ “Creating a Startup Item” (page 33) provides information about how to create startup items to support the launching of daemons on versions of Mac OS X prior to 10.4. ■ “Logging Errors and Warnings” (page 41) provides sample code for logging errors and warnings using syslog(3) and asl(3). ■ “Customizing Login and Logout” (page 45) provides information on how to customize the login process on older versions of Mac OS X. Organization of This Document 7 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. Introduction to System Startup Programming Topics 8 Organization of This Document 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. The Boot Process From the moment a user turns on a Mac OS X system to beyond the time the login window appears, Mac OS X executes a boot sequence that readies the system for use. If you provide system services to all users, you might need to execute some code during this process. The following sections explain the basic boot sequence and the places where your code can tie into it. BootROM When the power to a Macintosh computer is turned on, the BootROM firmware is activated. BootROM (which is part of the computer’s hardware) has two primary responsibilities: it initializes system hardware and it selects an operating system to run. BootROM has two components to help it carry out these functions: ■ POST (Power-On Self Test) initializes some hardware interfaces and verifies that sufficient memory is available and in a good state. ■ On PowerPC-based Macintosh computers, Open Firmware initializes the rest of the hardware, builds the initial device tree (a hierarchical representation of devices associated with the computer), and selects the operating system to use. On Intel-based Macintosh computers, EFI does basic hardware initialization and selects which operating system to use. If multiple installations of Mac OS X are available, BootROM chooses the one that was last selected by the Startup Disk System Preference. The user can override this choice by holding down the Option key while the computer boots, which causes Open Firmware or EFI to display a screen for choosing the boot volume. BootROM 9 2006-10-03 | © 2003, 2006 Apple Computer, Inc. All Rights Reserved. The Boot Process Note: On some legacy hardware, the same version of BootROM can start either Mac OS 9 or Mac OS X. Most current hardware can start only Mac OS X. BootX, boot.efi, and System Initialization Once BootROM is finished and a Mac OS X partition has been selected, control passes to the BootX (PowerPC) or boot.efi (Intel) boot loader. The principal job of this boot loader is to load the kernel environment. As it does this, the boot loader draws the “booting” image on the screen.
Recommended publications
  • The Linux Kernel Module Programming Guide
    The Linux Kernel Module Programming Guide Peter Jay Salzman Michael Burian Ori Pomerantz Copyright © 2001 Peter Jay Salzman 2007−05−18 ver 2.6.4 The Linux Kernel Module Programming Guide is a free book; you may reproduce and/or modify it under the terms of the Open Software License, version 1.1. You can obtain a copy of this license at http://opensource.org/licenses/osl.php. This book is distributed in the hope it will be useful, but without any warranty, without even the implied warranty of merchantability or fitness for a particular purpose. The author encourages wide distribution of this book for personal or commercial use, provided the above copyright notice remains intact and the method adheres to the provisions of the Open Software License. In summary, you may copy and distribute this book free of charge or for a profit. No explicit permission is required from the author for reproduction of this book in any medium, physical or electronic. Derivative works and translations of this document must be placed under the Open Software License, and the original copyright notice must remain intact. If you have contributed new material to this book, you must make the material and source code available for your revisions. Please make revisions and updates available directly to the document maintainer, Peter Jay Salzman <[email protected]>. This will allow for the merging of updates and provide consistent revisions to the Linux community. If you publish or distribute this book commercially, donations, royalties, and/or printed copies are greatly appreciated by the author and the Linux Documentation Project (LDP).
    [Show full text]
  • Mac OS 8 Update
    K Service Source Mac OS 8 Update Known problems, Internet Access, and Installation Mac OS 8 Update Document Contents - 1 Document Contents • Introduction • About Mac OS 8 • About Internet Access What To Do First Additional Software Auto-Dial and Auto-Disconnect Settings TCP/IP Connection Options and Internet Access Length of Configuration Names Modem Scripts & Password Length Proxies and Other Internet Config Settings Web Browser Issues Troubleshooting • About Mac OS Runtime for Java Version 1.0.2 • About Mac OS Personal Web Sharing • Installing Mac OS 8 • Upgrading Workgroup Server 9650 & 7350 Software Mac OS 8 Update Introduction - 2 Introduction Mac OS 8 is the most significant update to the Macintosh operating system since 1984. The updated system gives users PowerPC-native multitasking, an efficient desktop with new pop-up windows and spring-loaded folders, and a fully integrated suite of Internet services. This document provides information about Mac OS 8 that supplements the information in the Mac OS installation manual. For a detailed description of Mac OS 8, useful tips for using the system, troubleshooting, late-breaking news, and links for online technical support, visit the Mac OS Info Center at http://ip.apple.com/infocenter. Or browse the Mac OS 8 topic in the Apple Technical Library at http:// tilsp1.info.apple.com. Mac OS 8 Update About Mac OS 8 - 3 About Mac OS 8 Read this section for information about known problems with the Mac OS 8 update and possible solutions. Known Problems and Compatibility Issues Apple Language Kits and Mac OS 8 Apple's Language Kits require an updater for full functionality with this version of the Mac OS.
    [Show full text]
  • Linux Tutorial Last Updated: September 29 2021 for Windows Users
    VLAAMS SUPERCOMPUTER Innovative Computing CENTRUM for A Smarter Flanders Linux Tutorial Last updated: September 29 2021 For Windows Users Authors: Jasper Devreker (UGent), Ewan Higgs (UGent), Kenneth Hoste (UGent) Acknowledgement: VSCentrum.be Audience: This document is a hands-on guide for using the Linux command line in the context of the UGent HPC infrastructure. The command line (sometimes called ’shell’) can seems daunting at first, but with a little understanding can be very easy to use. Everything you do startsatthe prompt. Here you have the liberty to type in any commands you want. Soon, you will be able to move past the limited point and click interface and express interesting ideas to the computer using the shell. Gaining an understanding of the fundamentals of Linux will help accelerate your research using the HPC infrastructure. You will learn about commands, managing files, and some scripting basics. Notification: In$ commands this tutorial specific commands are separated from the accompanying text: These should be entered by the reader at a command line in a terminal on the UGent-HPC. They appear in all exercises preceded by a $ and printed in bold. You’ll find those actions ina grey frame. Button are menus, buttons or drop down boxes to be pressed or selected. “Directory” is the notation for directories (called “folders” in Windows terminology) or specific files. (e.g., “/user/home/gent/vsc400/vsc40000”) “Text” Is the notation for text to be entered. Tip: A “Tip” paragraph is used for remarks or tips. They can also be downloaded from the VSC website at https://www.vscentrum.be.
    [Show full text]
  • Xerox 4050/4090/4450/4650 Laser Printing Systems Message Guide
    XEROX Xerox 4050/4090/4450/4650 Laser Printing Systems Message Guide April 1995 720P93980 Xerox Corporation 701 S. Aviation Boulevard El Segundo, CA 90245 © 1991, 1992, 1993, 1994, 1995 by Xerox Corporation. All rights reserved. Copyright protection claimed includes all forms and matters of copyrightable material and information now allowed by statutory or judicial law or hereinafter granted, including without limitation, material generated from the software programs which are displayed on the screen, such as icons, screen displays, looks, etc. Printed in the United States of America Publication number: 720P93980 Xerox® and all Xerox products mentioned in this publication are trademarks of Xerox Corporation. Products and trademarks of other companies are also acknowledged. Changes are periodically made to this document. Changes, technical inaccuracies, and typographic errors will be corrected in subsequent editions. This document was created on the Xerox 6085 Professional Computer System using GobalView software. The typeface is Optima. Table of contents Introduction vii Document conventions vii Related publications viii 1. Compress command messages 1-1 2. Data Capture Utility messages 2-1 System failure or reload messages 2-6 3. Disk Save and Restore command messages 3-1 4. File Conversion Utility messages 4-1 5. General Floppy Utility messages 5-1 FLF messages 5-15 6. Forms Description Language compilation messages 6-1 7. Host Interface Processor messages 7-1 8. Interpress Font Utility messages 8-1 9. Operating System Software messages 9-1 OS level 0: Confirmation messages 9-1 OS level 1: Informational messages 9-7 OS level 2: Routine maintenance messages 9-37 OS level 3: Printer problem messages 9-59 OS level 4: System or tape problem messages 9-64 OS level 6: Job integrity problem messages 9-68 OS level 7: System problem messages 9-88 OS level 8: Probable severe software errors 9-93 OS level 9: Probable severe hardware errors 9-99 10.
    [Show full text]
  • Chapter 1. Origins of Mac OS X
    1 Chapter 1. Origins of Mac OS X "Most ideas come from previous ideas." Alan Curtis Kay The Mac OS X operating system represents a rather successful coming together of paradigms, ideologies, and technologies that have often resisted each other in the past. A good example is the cordial relationship that exists between the command-line and graphical interfaces in Mac OS X. The system is a result of the trials and tribulations of Apple and NeXT, as well as their user and developer communities. Mac OS X exemplifies how a capable system can result from the direct or indirect efforts of corporations, academic and research communities, the Open Source and Free Software movements, and, of course, individuals. Apple has been around since 1976, and many accounts of its history have been told. If the story of Apple as a company is fascinating, so is the technical history of Apple's operating systems. In this chapter,[1] we will trace the history of Mac OS X, discussing several technologies whose confluence eventually led to the modern-day Apple operating system. [1] This book's accompanying web site (www.osxbook.com) provides a more detailed technical history of all of Apple's operating systems. 1 2 2 1 1.1. Apple's Quest for the[2] Operating System [2] Whereas the word "the" is used here to designate prominence and desirability, it is an interesting coincidence that "THE" was the name of a multiprogramming system described by Edsger W. Dijkstra in a 1968 paper. It was March 1988. The Macintosh had been around for four years.
    [Show full text]
  • Absolute BSD—The Ultimate Guide to Freebsd Table of Contents Absolute BSD—The Ultimate Guide to Freebsd
    Absolute BSD—The Ultimate Guide to FreeBSD Table of Contents Absolute BSD—The Ultimate Guide to FreeBSD............................................................................1 Dedication..........................................................................................................................................3 Foreword............................................................................................................................................4 Introduction........................................................................................................................................5 What Is FreeBSD?...................................................................................................................5 How Did FreeBSD Get Here?..................................................................................................5 The BSD License: BSD Goes Public.......................................................................................6 The Birth of Modern FreeBSD.................................................................................................6 FreeBSD Development............................................................................................................7 Committers.........................................................................................................................7 Contributors........................................................................................................................8 Users..................................................................................................................................8
    [Show full text]
  • Pooch Manual In
    What’s New As of August 21, 2011, Pooch is updated to version 1.8.3 for use with OS X 10.7 “Lion”: Pooch users can renew their subscriptions today! Please see http://daugerresearch.com/pooch for more! On November 17, 2009, Pooch was updated to version 1.8: • Linux: Pooch can now cluster nodes running 64-bit Linux, combined with Mac • 64-bit: Major internal revisions for 64-bit, particularly updated data types and structures, for Mac OS X 10.6 "Snow Leopard" and 64-bit Linux • Sockets: Major revisions to internal networking to adapt to BSD Sockets, as recommended by Apple moving forward and required for Linux • POSIX Paths: Major revisions to internal file specification format in favor of POSIX paths, recommended by Apple moving forward and required for Linux • mDNS: Adapted usage of Bonjour service discovery to use Apple's Open Source mDNS library • Pooch Binary directory: Added Pooch binary directory support, making possible launching jobs using a remotely-compiled executable • Minor updates and fixes needed for Mac OS X 10.6 "Snow Leopard" Current Pooch users can renew their subscriptions today! Please see http://daugerresearch.com/pooch for more! On April 16, 2008, Pooch was updated to version 1.7.6: • Mac OS X 10.5 “Leopard” spurs updates in a variety of Pooch technologies: • Network Scan window • Preferences window • Keychain access • Launching via, detection of, and commands to the Terminal • Behind the Login window behavior • Other user interface and infrastructure adjustments • Open MPI support: • Complete MPI support using libraries
    [Show full text]
  • Carbon Copy Cloner Documentation: English
    Carbon Copy Cloner Documentation: English Getting started with CCC System Requirements, Installing, Updating, and Uninstalling CCC CCC License, Registration, and Trial FAQs Trouble Applying Your Registration Information? Establishing an initial backup Preparing your backup disk for a backup of Mac OS X Restoring data from your backup What's new in CCC Features of CCC specific to Lion and greater Release History Carbon Copy Cloner's Transition to a Commercial Product: Frequently Asked Questions Credits Example backup scenarios I want to clone my entire hard drive to a new hard drive or a new machine I want to backup my important data to another Macintosh on my network I want to backup multiple machines or hard drives to the same hard drive I want my backup task to run automatically on a scheduled basis Backing up to/from network volumes and other non-HFS volumes I want to back up my whole Mac to a Time Capsule or other network volume I want to defragment my hard drive Backup and archiving settings Excluding files and folders from a backup task Protecting data that is already on your destination volume Managing previous versions of your files Automated maintenance of CCC archives Advanced Settings Some files and folders are automatically excluded from a backup task The Block-Level Copy Scheduling Backup Tasks Scheduling a task and basic settings Performing actions Before and After the backup task Deferring and skipping scheduled tasks Frequently asked questions about scheduled tasks Email and Growl notifications Backing Up to Disk Images
    [Show full text]
  • UCL for Freebsd
    UCL for FreeBSD A universal config language for (almost) everything in FreeBSD Allan Jude -- ScaleEngine Inc. [email protected] twitter: @allanjude Introduction Allan Jude ● 13 Years as FreeBSD Server Admin ● FreeBSD docs committer (focus: ZFS, bhyve, ucl, xo) ● Co-Author of “FreeBSD Mastery: ZFS” ● Architect of the ScaleEngine CDN (HTTP and Video) ● Host of BSDNow.tv & TechSNAP.tv Podcasts ● Extensive work with Puppet to manage our 100+ servers in 35 data centers in 12 countries ● Lots of work with ZFS to manage large collections of videos, extremely large website caches, and the pkg mirror for PCBSD Impetus At EuroBSDCon 2014 in Sofia, Jordan Hubbard ([email protected]) gave the opening keynote Among the recommendations for how FreeBSD could be improved and made easier to manage was to move away from the ‘one config file format per utility’ Jordan, being from Apple, suggested the binary XML plists used by launchd. I really didn’t want the “one true format” to be XML. Why is this a “Good Idea”™? ● Includes allow for more readable, structured, and upgradable config files ● Overlays separate the defaults from your site wide settings, and from your local settings (like defaults/rc.conf rc.conf rc.conf.local) ● Includes allow packages to install default settings (installing apache or nginx adds its log rotation to newsyslog) ● ● What is UCL ● UCL -- universal configuration language ● Inspired by bind/nginx style configuration file that all sysadmins know well ● Fully compatible with JSON, but more liberal in what it accepts, so users do
    [Show full text]
  • Introduction to Apple Events 3
    CHAPTER 3 Introduction to Apple Events 3 This chapter introduces Apple events and the Apple Event Manager. Later chapters describe how your application can use the Apple Event Manager to respond to and send Apple events, locate Apple event objects, and record Apple events. The interapplication communication (IAC) architecture for Macintosh computers consists of five parts: the Edition Manager, the Open Scripting Architecture (OSA), the Apple Event Manager, the Event Manager, and the Program-to-Program Communications (PPC) Toolbox. The chapter “Introduction to Interapplication Communication” in this book provides an overview of the relationships among these parts. The Apple Event Registry: Standard Suites defines both the actions performed by the standard Apple events, or “verbs,” and the standard Apple event object classes, which can be used to create “noun phrases” describing objects on which Apple events act. If your application uses the Apple Event Manager to respond to some of these standard Apple events, you can make it scriptable—that is, capable of responding to scripts written in a scripting language such as AppleScript. In addition, your application can 3 use the Apple Event Manager to create and send Apple events and to allow user actions Introduction to Apple Events in your application to be recorded as Apple events. Before you use this chapter or any of the other chapters about the Apple Event Manager, you should be familiar with the chapters “Event Manager” in Inside Macintosh: Macintosh Toolbox Essentials and “Process Manager” in Inside Macintosh: Processes. This chapter begins by describing Apple events and some of the data structures they contain.
    [Show full text]
  • Mac OS X Intro for UNIX Users
    Mac OS X An Introduction for UNIX Users Leon Towns-von Stauber, Occam's Razor Seattle BSD Users Group, October 2004 http://www.occam.com/osx/ X Contents Opening Remarks.............................3 Where Did Mac OS X Come From?.....5 What is Mac OS X?..........................13 A New Kind of UNIX........................25 A Different Kind of UNIX.................28 Why Use Mac OS X?.........................60 Resources.......................................63 Closing Remarks.............................67 X Opening Remarks 3 This is a technical introduction to Mac OS X, mainly targeted to experienced UNIX users for whom OS X is at least relatively new Some emphasis on comparisons with FreeBSD I'm assuming basic familiarity with operating system design Where I'm coming from: UNIX user and some-time admin since 1990 Full-time UNIX admin since 1995 NeXTstep user and admin since 1991 This presentation covers primarily Mac OS X 10.3.5 (Darwin 7.5) X Legal Notices 4 This presentation Copyright © 2003-2004 Leon Towns-von Stauber. All rights reserved. Trademark notices Apple®, Mac®, Macintosh®, Mac OS®, Aqua®, Finder™, Quartz™, Cocoa®, Carbon®, AppleScript®, Rendezvous™, Panther™, and other terms are trademarks of Apple Computer. See <http:// www.apple.com/legal/appletmlist.html>. NeXT®, NeXTstep®, OpenStep®, and NetInfo® are trademarks of NeXT Software. See <http://www.apple.com/legal/nexttmlist.html>. PowerPC™ is a trademark of International Business Machines. Java™ is a trademark of Sun Microsystems. Other trademarks are the property of their
    [Show full text]
  • Daemon Threads
    Daemon threads Your operating system has various threads that provide services to user threads. That’s their sole purpose: to serve user threads. The term originated with the Unix operating system, but most operating systems have them in one form or another, with slightly differing properties. Examples are: • In Unix, crond is job scheduler, running jobs in the background. Line printer daemon lpd manages printer spooling. • In Windows systems, daemons are called Windows services. One such is Prefetch-and-Superfetch, which caches frequently used files and other components to RAM. The DNS Client resolves domain names to IP addresses. • In Java, the garbage collector is a daemon, continuously finding objects that cannot be reached from the Java program and putting the memory they occupy on a “free list” so the memory can be used for some other purpose. We won’t be writing Java programs that use daemon threads. (Look at the next page for a realistic use of a daemon thread.) Nevertheless, a basic understanding of daemons, including where the word came from, is useful. The basic property of a Java daemon thread In Java, suppose your main-program thread is named t. Suppose t creates and starts threads t1, t2, and t3. Suppose also that it has made t3 a daemon (we show how to do this later). Here is the basic difference be- tween t3 and the other threads: When thread t, t1, and t2 die (i.e. complete method run()), daemon thread t3 is killed. Thus, as long as one normal thread is alive, daemon threads stay alive.
    [Show full text]