Dan Pilch

Personal and Professional blog

View My GitHub Profile

2 April 2025

Debugging a Slow /usr/bin/login on macOS (WIP)

by Dan Pilch

Debugging a Slow /usr/bin/login on macOS (WIP)

Work-in-progress notes on figuring out why /usr/bin/login is painfully slow on my MacBook (Apple Silicon, arm64).

šŸ¤” The Problem

A couple of days ago I noticed that terminal sessions using /usr/bin/login are significantly slower than expected and take 13 minutes to start. This impacts not just Terminal.app and iTerm2, but does not affect vs code terminal sessions…

šŸ“ Initial Observations

šŸ” Investigation So Far

1. Shell Startup Profiling

Ran the following to trace shell init:

zsh -i -x -c exit

Findings:

2. Login Process Timing

time login -f $USER

Still slower than expected. Indicates delay might be deeper than shell config.

3. Console Logs

Checked logs via:

log show --predicate 'eventMessage contains "login"' --last 5m

Not much of note yet. May need more specific queries.

4. PAM Modules

Looking into /etc/pam.d/login in case there are any unusual or slow modules.

🧵 Slack Thread Highlights

Troubleshooting this in Slack led to some additional context:

🚫 Tooling Limitations

dtruss is Broken on Apple Silicon šŸ˜ž

Tried to trace with:

dtruss login

But on M1/M2 MacBooks:

dtrace: system integrity protection is on, some features will not be available ksh: dtrace: operation not permitted

Even with SIP disabled, dtruss often fails or panics the machine.

Currently exploring alternatives like:

Using fs_usage with a Script

I tried this script to watch /usr/bin/login as soon as it spawns:

#!/bin/bash
echo "Waiting for /usr/bin/login to start..."

while true; do
    pid=$(pgrep -f '^/usr/bin/login' | head -n1)
    if [[ -n "$pid" ]]; then
        echo "Found login with PID $pid"
        echo "Attaching fs_usage..."
        sudo fs_usage -w -f filesys -e $pid | gawk '$NF ~ /login/ { print }' | tee loginfs.log
        break
    fi
    sleep 0.5
done

This should help isolate file access patterns right at the moment /usr/bin/login kicks in.

āœ… Next Steps

🧠 Theories


Will keep updating this post as I dig further. If you’ve run into this issue or have debugging tips for arm64 macOS, reach out!

tags: