Free tools Windows power users keep installed
One-click scans. No signup required.
iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
A packaged Mac backend that launches lsof by its bare name can log “lsof: command not found” even when lsof is installed. In the case documented by Mihai Perdum on DEV Community, the binary was at /usr/sbin/lsof, but the backend’s runtime PATH did not include /usr/sbin. The spawn failed, the code that identifies the process holding the port never ran, and the port stayed occupied. The fix has two parts: resolve lsof from known absolute locations before searching PATH, and signal only TCP listeners rather than every process touching the port.
Why the failure appears only in the packaged app
When you run a backend from Terminal, it inherits your login shell’s PATH, which usually includes the system administration directories. A packaged app does not inherit that environment. It receives whatever environment its launcher builds, and that can be much narrower. The lookup failure is easy to miss because nothing in a development run reproduces it.
What the author measured
- On the author’s host,
lsoflived at/usr/sbin/lsof. - The PATH the packaged backend actually received, as the author logged it, did not contain
/usr/sbin. - A bare-name spawn of
lsoftherefore failed, and the reclaim code never reached the step that inspects or signals the port holder.
These are the author’s machine measurements. Other Macs, macOS versions, and launchers may build a different PATH, so the only reliable check is the one below.
Check the PATH your shipped build uses
- At backend startup, log the PATH variable the process received, along with whether each known
lsoflocation exists. - Build the app and launch the packaged bundle the way users do, not through a development server.
- Read the log and compare it with the output of
echo $PATHin Terminal. The difference is the bug. - If
/usr/sbinis missing from the logged PATH, a barelsofcall will fail in that build.
Why the reclaim branch never ran
The reclaim logic depends on lsof output to find the process holding the port. When the spawn fails, there is no output to act on, so the branch is skipped or abandoned. The application may log a warning and carry on, which makes the failure look like a minor message rather than a broken feature.
#1 Best Overall
- SUPERCHARGED BY M5 — The 14-inch MacBook Pro with M5 brings next-generation speed and powerful on-device AI to personal, professional, and creative tasks. Featuring all-day battery life and a breathtaking Liquid Retina XDR display with up to 1600 nits peak brightness, it’s pro in every way.*
- HAPPILY EVER FASTER — Along with its faster CPU and unified memory, M5 features a more powerful GPU with a Neural Accelerator built into each core, delivering faster AI performance. So you can blaze through demanding workloads at mind-bending speeds.
- BUILT FOR APPLE INTELLIGENCE — Apple Intelligence is the personal intelligence system that helps you write, express yourself, and get things done effortlessly. With groundbreaking privacy protections, it gives you peace of mind that no one else can access your data — not even Apple.*
- ALL-DAY BATTERY LIFE — MacBook Pro delivers the same exceptional performance whether it’s running on battery or plugged in.
- APPS FLY WITH APPLE SILICON — All your favorites, including Microsoft 365 and Adobe Creative Cloud, run lightning fast in macOS.*
The author frames this as a design problem rather than a one-off bug:
“A branch that always fires is not an edge case, it is the design — and when the always-firing branch is the one that gives up, you have shipped the giving up.” — Mihai Perdum
Rank #2
SaleApple 2026 MacBook Pro Laptop with Apple M5 Pro chip with 18-core CPU and 20-core GPU: Built for AI, 16.2-inch Liquid Retina XDR Display, 24GB Unified Memory, 1TB SSD, Wi-Fi 7; Space Black
- FAST RUNS IN THE FAMILY — The 16-inch MacBook Pro with the M5 Pro or M5 Max chip brings next-generation speed and powerful on-device AI to personal, professional, and creative tasks. With all-day battery life, double the starting storage,* and a breathtaking Liquid Retina XDR display, it’s pro in every way.*
- BUCKLE UP — Along with a next-generation CPU, faster unified memory, and up to 2x faster SSD storage,* M5 Pro and M5 Max feature a more powerful GPU with a Neural Accelerator built into each core, delivering faster AI performance and on-device training capabilities. So you can blaze through demanding workloads at mind-bending speeds.
- BUILT FOR AI — Apple silicon, and every major component that powers it, is designed to run demanding on-device AI workloads like LLM inference and training. And Apple Intelligence helps you write, express yourself, and get things done effortlessly with groundbreaking privacy protections at every step.*
- ALL-DAY BATTERY LIFE — MacBook Pro delivers the same exceptional performance whether it’s running on battery or plugged in.*
- MACOS RUNS APPS FAST — All your go-to apps run lightning fast in macOS, including built-in apps like FaceTime and Messages. Plus, built-in virus protection and free software updates help keep your Mac running smoothly and securely.
In practice, treat “the tool could not run” as a normal outcome with its own handling. It should stop the reclaim with an error that names the tool and the locations checked, not pass silently.
Resolve lsof without relying on PATH alone
The author’s preferred fix is to find the executable explicitly. The steps below follow his order.
Rank #3
- FAST RUNS IN THE FAMILY — The 16-inch MacBook Pro with the M5 Pro or M5 Max chip brings next-generation speed and powerful on-device AI to personal, professional, and creative tasks. With all-day battery life, double the starting storage,* and a breathtaking Liquid Retina XDR display, it’s pro in every way.*
- BUCKLE UP — Along with a next-generation CPU, faster unified memory, and up to 2x faster SSD storage,* M5 Pro and M5 Max feature a more powerful GPU with a Neural Accelerator built into each core, delivering faster AI performance and on-device training capabilities. So you can blaze through demanding workloads at mind-bending speeds.
- BUILT FOR AI — Apple silicon, and every major component that powers it, is designed to run demanding on-device AI workloads like LLM inference and training. And Apple Intelligence helps you write, express yourself, and get things done effortlessly with groundbreaking privacy protections at every step.*
- ALL-DAY BATTERY LIFE — MacBook Pro delivers the same exceptional performance whether it’s running on battery or plugged in.*
- MACOS RUNS APPS FAST — All your go-to apps run lightning fast in macOS, including built-in apps like FaceTime and Messages. Plus, built-in virus protection and free software updates help keep your Mac running smoothly and securely.
- Check known absolute locations first, in order:
/usr/sbin/lsof,/usr/bin/lsof, then/opt/homebrew/bin/lsof. These are candidates in the author’s code. They are not guaranteed to exist on every Mac, and a missing one is simply skipped. - If none of them exists, walk the PATH entries in order and check each directory for an executable named
lsof. Ignore empty PATH components. - If nothing is found, fail with an error that lists every candidate path checked, in order. A message such as “lsof not found” alone does not show where resolution went wrong; a list of checked paths does.
- Use the resolved absolute path for every later call to
lsof.
Widening PATH as supplemental hardening
The author also appended /usr/sbin:/sbin to the backend’s POSIX PATH. This is a reasonable extra safeguard because other system tools may be missing from the same narrow environment. It is not the primary fix. The resolver should still work if the launch environment changes again, which is why the absolute-path lookup comes first.
Signal only the listener
Finding lsof is only half the problem. The query that feeds the signal step decides which processes get killed. The author’s port probe on port 8874 compared two commands:
Rank #4
- SUPERCHARGED BY M5 — The 14-inch MacBook Pro with M5 brings next-generation speed and powerful on-device AI to personal, professional, and creative tasks. Featuring all-day battery life and a breathtaking Liquid Retina XDR display with up to 1600 nits peak brightness, it’s pro in every way.*
- HAPPILY EVER FASTER — Along with its faster CPU and unified memory, M5 features a more powerful GPU with a Neural Accelerator built into each core, delivering faster AI performance. So you can blaze through demanding workloads at mind-bending speeds.
- BUILT FOR APPLE INTELLIGENCE — Apple Intelligence is the personal intelligence system that helps you write, express yourself, and get things done effortlessly. With groundbreaking privacy protections, it gives you peace of mind that no one else can access your data — not even Apple.*
- ALL-DAY BATTERY LIFE — MacBook Pro delivers the same exceptional performance whether it’s running on battery or plugged in.
- APPS FLY WITH APPLE SILICON — All your favorites, including Microsoft 365 and Adobe Creative Cloud, run lightning fast in macOS.*
| Command | Result in the author’s probe |
|---|---|
lsof -ti TCP:8874 |
Returned a listener PID and a connected client PID |
lsof -ti TCP:8874 -sTCP:LISTEN |
Returned only the listener PID |
The -t flag prints bare PIDs, and -i TCP:8874 selects TCP sockets on that port. Without a state filter, lsof reports any socket touching the port. A client with an established connection to the port is included, even though it is not the process holding the port open for listening. The author puts it this way:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Repair Windows errors before they cause bigger problems3Scan for outdated or missing drivers - takes under a minute“The bare query does not mean “who owns this port”, it means “who currently has a socket touching this port”, and a client holding an established connection qualifies.” — Mihai Perdum
Best Value
Apple 2025 MacBook Pro Laptop with Apple M5 chip with 10‑core CPU and 10‑core GPU: Built for AI, 14.2-inch Liquid Retina XDR Display, 16GB Unified Memory, 1TB SSD Storage; Silver
- SUPERCHARGED BY M5 — The 14-inch MacBook Pro with M5 brings next-generation speed and powerful on-device AI to personal, professional, and creative tasks. Featuring all-day battery life and a breathtaking Liquid Retina XDR display with up to 1600 nits peak brightness, it’s pro in every way.*
- HAPPILY EVER FASTER — Along with its faster CPU and unified memory, M5 features a more powerful GPU with a Neural Accelerator built into each core, delivering faster AI performance. So you can blaze through demanding workloads at mind-bending speeds.
- BUILT FOR APPLE INTELLIGENCE — Apple Intelligence is the personal intelligence system that helps you write, express yourself, and get things done effortlessly. With groundbreaking privacy protections, it gives you peace of mind that no one else can access your data — not even Apple.*
- ALL-DAY BATTERY LIFE — MacBook Pro delivers the same exceptional performance whether it’s running on battery or plugged in.
- APPS FLY WITH APPLE SILICON — All your favorites, including Microsoft 365 and Adobe Creative Cloud, run lightning fast in macOS.*
He also describes the state filter as the key safeguard:
“
-sTCP:LISTENis the whole defence:” — Mihai Perdum
A reclaim routine should therefore:
- Query with
-sTCP:LISTENbefore sending any signal. - Send signals only to the PIDs that query returns.
- Apply application-specific checks before killing anything, such as confirming that the PID belongs to a previous instance of your own backend. A successful
lsofrun does not by itself make a kill safe.
Verify the fix
- Confirm the startup log shows the absolute path that was resolved for
lsof. - Leave a client connected to a stale listener on the port, start the packaged app, and confirm that only the listener is terminated and the client connection survives.
- Confirm that a failed lookup produces an error listing every candidate path checked.
The author reports a test run of 43 passed, 0 failed, and 9 ignored for his project. Those results come from his codebase and are not independently reproduced here.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →What this account does and does not establish
The sources for this article are a single developer’s write-up and its published excerpts. The PATH contents, probe output, and test counts describe the author’s environment. The article does not establish how other macOS versions, launchers, or package formats set PATH, and it does not cite Apple documentation or lsof maintainer guidance. The quoted sentences are the author’s assertions. Check lsof behavior and the runtime PATH inside your own packaged build before acting on process IDs.
Quick Recap
“
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

