- Reference 29.1<br>System Initialization
- Reference 29.2<br>User Session
- Reference 29.3<br>Sleep Modes, Logout, and Shutdown
- Reference 29.4<br>Startup Shortcuts
- Reference 29.5<br>System Initialization Troubleshooting
- Reference 29.6<br>User Session Troubleshooting
- Exercise 29.1<br>Examine System Startup
- Exercise 29.2<br>Use Single-User Mod
Reference 29.2
User Session
Eventually, after enough system processes have started, the system begins the processes responsible for managing the user session.
The three main OS X user session stages are, in order:
- loginwindow—This is the process responsible for presenting the login screen and eventually logging the user in to the system. Successful completion of this stage results in initialization of the user environment, thus allowing user applications to run.
- User launchd—This process works in conjunction with the loginwindow process to initialize the user environment and start any user processes or applications.
- User environment—This is the “space” in which the user’s processes and applications exist when she is logged in to the system. Obviously, the user environment is maintained by the loginwindow and user launchd processes.
Login Window
A soon as the system has started enough processes to present the login window, the system launchd process starts /System/Library/CoreServices/loginwindow.app. The loginwindow process has the ability to run as both a background process and a graphical interface application. The loginwindow coordinates the login screen and, along with the opendirectoryd process, authenticates the user. After authentication, the loginwindow, in conjunction with the user’s launchd, also initializes the graphical interface user environment and continues
to run as a background process to maintain the user session.
By default in OS X, the user must authenticate using the login screen, or the loginwindow can be set to automatically authenticate a user at startup. As covered previously, the system also automatically logs in a user if she provided authentication to unlock FileVault 2 during startup. The loginwindow settings are stored in the /Library/Preferences/com.apple
.loginwindow.plist preference file. As covered in Lesson 6, “User Accounts,” you can configure loginwindow settings from Users & Groups preferences.
If no users are logged in to the Mac, the loginwindow process is owned by the root user. Once a user successfully authenticates, the loginwindow process switches ownership to this user and then proceeds to set up the graphical interface user environment with help from the user’s launchd.
The User’s launchd
The moment a user is authenticated, the system launchd process starts another instance of launchd that is also owned by the authenticated user. All user processes and applications, even those that the user manually opens, are started by the user-specific launchd process. If fast user switching is enabled, the system launchd process starts additional loginwindow and launchd processes to initialize and maintain each user’s environment.
The user’s loginwindow and launchd processes set up the graphical interface user environment by:
- Retrieving the user account information from opendirectoryd and applying any account settings
- Configuring the mouse, keyboard, and system sound using the user’s preferences
- Loading the user’s computing environment: preferences, environment variables, devices and file permissions, and keychain access
- Opening the Dock (also responsible for Mission Control and Dashboard), Finder, and SystemUIServer (responsible for user interface elements like menu extras on the right side of the menu bar)
- Automatically opening the user’s login items
- Automatically resuming any application that was open before the last logout, by default in OS X
It’s important to understand the differences among the various autostarting mechanisms in OS X: launch daemons, startup items, launch agents, and login items. Again, launch daemons and startup items are started during system initialization by the system launchd process on behalf of the root user. On the other hand, launch agents and login items are only started on behalf of a specific user. In other words, launch daemons and startup items affect the system as a whole, while launch agents and login items affect individual users.
Specifically, launch agents are started by the user’s launchd process on behalf of the user. Launch agents can be started at any time as long as the user’s launchd process is running. Most launch agents are started during the initialization of the user environment, but they could also be started afterward or on a regular repeating basis depending on need. Launch agents provided by the system can be found in /System/Library/LaunchAgents, whereas third-party launch agents should be located in either /Library/LaunchAgents or ~/Library/LaunchAgents.
Finally, login items are started only at the very end of the initialization of the user environment. The loginwindow process, again with help from the user’s launchd process, is responsible for starting a user’s login items. The user’s login item list is stored in the ~/Library/Preferences/loginwindow.plist preference file. As covered previously in Lesson 6, “User Accounts,” you can configure a user’s login item list from Users & Groups preferences.
Again, from Activity Monitor you can examine the user’s launchd process and the resulting user processes. It’s especially helpful if the process list is sorted by “All Processes, Hierarchically.”
The User Environment
The user-owned launchd and loginwindow processes continue to run as long as the user is logged in to the session. The user’s launchd process starts all user processes and applications, while the user’s loginwindow process monitors and maintains the user session.
The user’s loginwindow process monitors the user session by:
- Managing logout, restart, and shutdown procedures
- Managing the Force Quit Applications window, which includes monitoring the currently active applications and responding to user requests to forcibly quit applications
- Writing any standard-error output to the user’s console.log file
While the user is logged in to the session, the user’s launchd process automatically restarts any user application that should remain open, such as the Finder or the Dock. If the user’s loginwindow process is ended, whether intentionally or unexpectedly, all the user’s applications and processes immediately quit without saving changes. If this happens, the system launchd process then automatically restarts the loginwindow process as if the Mac had just started up. In other words, the loginwindow, depending on configuration, either displays the login screen or automatically logs in the specified user.