Mac OS X has always supported more than one user at a time, but until OS X 10.3 that was limited to root and a single user at once. In October 2003, Mac OS X Panther introduced multiple concurrent users, and the ability to change user without logging out, by fast user switching (FUS). This article explains how this works, how it differs from changing users by logging out and back in, and which to use when.
In macOS Ventura, the usual controls for fast user switching are in the menu bar or Control Centre, as enabled in System Settings. Macs whose keyboards support Touch ID can instead use the Touch ID sensor: on a Touch Bar, keep touching the sensor until prompted to press it until it clicks; on a dedicated Touch ID key, press and hold the key until it clicks. You’ll then be presented with a choice of users to switch to. When you select a different user, the display will next show a login window for that user account.
This is completely different from logging out of the current user account using the Apple menu command, then logging into a different user account. When you use FUS, your Mac doesn’t log out of the current user account, but additionally logs into the other user account, leaving it with three active accounts: root, the first user, and the second. These differences become clearer if you examine what happens in both user logout and fast user switching.
Logging a user out is initiated by a kAELogOutEvent AppleEvent. loginwindow engages SessionLogoutManager, displays the confirmation dialog, starts a countdown timer, and enters its first logout state LogoutConfirmation.
Once logout is confirmed in that dialog, loginwindow then passes rapidly through its sequence of logout states, whose names reveal its actions:
These are normally completed within about 0.5 seconds of confirmation, at the end of which no user is logged in, and the main login window is displayed, inviting you to log in as a user. When you do so, all processes for the previous user have been closed, and those for the new user will be started up during a fresh login sequence.
Fast User Switch
Performing a fast user switch to a different user is initiated differently, for example in Control Centre. This is initially handled by
opendirectoryd to determine the new user, then handed over to loginwindow to manage. That enters its sequence of login states to accomplish the switch:
TAL is the macOS Transparent App Lifecycle, which helps loginwindow restore sessions across reboots using the many folders containing saved states in the ~/Library/Saved Application State folder.
This takes considerably longer to complete, around 25 seconds in all, at the end of which both users are logged in, and the second user’s Finder and any open apps are ready for use. Processes still running for the first user will continue, but can’t receive local keyboard/mouse/trackpad input, and don’t output to the display or audio; as far as those processes are concerned, it’s as if the display has gone to sleep. All user input and output is thus connected to the second user.
In macOS, processes are organised into sessions. Once a user has logged in, there are two sessions: the root session, and a single user login session. User processes in the login session can access those in the root session, and do so to use system services.
When a second user login session is started with FUS, there are then three sessions: the root session continues, and both user login sessions are active, and able to access system services running in the root session. However, the two user login sessions can’t communicate or interact directly, ensuring that they remain secure. Internally, each user login session has a unique session ID, used to distinguish between them.
There’s one important change to behaviour when running multiple login sessions: when the front login session calls for the Mac to be shut down or restarted. Normally, as loginwindow shuts down user processes, the user is given the opportunity to save any unsaved documents and changes. As that can’t be done for the other login sessions still active, the user of the front login session is warned that other login sessions will lose their unsaved changes before shutdown or restart proceeds.
Because two or more user login sessions are running at the same time, once you’ve used FUS to switch to a different user the resources used by processes in all open login sessions will be significantly greater than with just a single login user open. You can check this in Activity Monitor, provided that you change its View setting to All Processes rather than My Processes. If this presents a problem, you can quit all open apps before switching using FUS, but that defeats the purpose of FUS, and there are still plenty of processes in the first login session that you can’t quit. Until a second login session is opened with FUS, it incurs no memory or processing overhead.
Fast user switching is an ideal way for another user to access a Mac while it’s still being used by a first user. Switching is fast, but requires sufficient resources, particularly memory, to allow both sessions to operate at the same time. It also requires separate Home folders for each user.
Logging out and back in again without FUS is an established method of addressing many problems that occur in user space. Although at one time it was useful for tackling problems with WindowServer, this is now less likely to succeed because that runs in its own login session, so a full restart may be needed. If a problem can be fixed by shutting down user processes, then try logging out of that user account; because FUS doesn’t perform any logging out, it’s not going to help at all, and could even exacerbate problems.
loginwindow on this blog
Apple’s Multiple User Environment Programming Topics, last revised in 2013.