🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)
🪟 Windows TippsThe Gemini desktop app is now available for Windows(11.09.2026 um 17:06 Uhr)
⚠️ Malware / Trojaner / VirenWindows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC(10.09.2026 um 20:11 Uhr)
⚠️ Malware / Trojaner / VirenVorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf(11.09.2026 um 09:35 Uhr)
🕵️ SicherheitslückenMicrosoft geht endlich eines der nervigsten Probleme von Windows 11 an(11.09.2026 um 11:58 Uhr)
💾 IT Security ToolsSysinternals Suite(11.09.2026 um 12:00 Uhr)
🕵️ SicherheitslückenDefender 0-Day ShieldBreak (CVE-2026-69414) nicht sauber gepatcht - BornCity(11.09.2026 um 12:52 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 4 Min Lesezeit
0

Tips for Running Stable Background ML Inference on macOS

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

📝 Originally published (in Japanese) at forge.workstyle.tech.




Running an inference service as a background process on macOS, with a Linux server mindset, can lead to subtle issues. Things like "a one-liner that works on Linux doesn't work on Mac" or "grepping logs results in garbled text errors and crashes" — these are minor but time-consuming problems.



This article compiles a collection of short tips gathered from running a Seed-VC based voice conversion service (FastAPI + uvicorn, local 127.0.0.1:8770) as a background process on macOS. It focuses on macOS-specific pitfalls not covered in Linux-centric articles.






TIP 1: setsid / timeout are not available on macOS



First, it's important to note that macOS (BSD-based) does not include GNU coreutils' setsid or timeout by default. If you use these commands, which are used for backgrounding and timed execution on Linux, directly in a Mac script, you'll get a command not found error.



There are two solutions:




  • Install coreutils via Homebrew and use gsetsid/gtimeout

  • Use standard tools as alternatives (next TIP)



For background scripts that avoid external dependencies, using standard tools as alternatives is a safer option.






TIP 2: Use nohup + disown for background processes



In environments without setsid, the combination of nohup and disown is reliable for keeping processes alive even after closing the shell.




CODE
# Run the inference service as a background process
nohup bash scripts/start-backend.sh > backend.log 2>&1 &
disown








  • nohup ... Ignores hangup signals (SIGHUP), keeping the process alive even after the terminal is closed


  • > backend.log 2>&1 ... Redirects standard output and standard error to a log file


  • & ... Runs the process in the background


  • disown ... Removes the job from the shell's job table, preventing it from being terminated when the shell is closed



While nohup alone usually keeps the process alive, adding disown ensures that closing the terminal won't accidentally terminate the process.






TIP 3: tr / grep fail with binary data in logs → use LC_ALL=C



This was the most problematic issue on Mac. Inference logs may contain progress bar control characters or, occasionally, garbled multibyte sequences. When processed by macOS's tr or grep, you'll see:




tr: Illegal byte sequence




This happens because the locale is set to UTF-8, causing invalid byte sequences to be treated as "invalid characters" and throwing an exception.



The solution is to set the locale to C (pass-through as byte sequences) for those commands.




CODE
# Remove unwanted control characters from logs (avoids Illegal byte sequence)
LC_ALL=C tr -d '\r' < backend.log > backend.clean.log
LC_ALL=C grep "ERROR" backend.log






Setting LC_ALL=C treats text as "bytes" rather than "characters," preventing crashes due to invalid sequences. This is safer for pipelines that process or search logs programmatically.






TIP 4: Wait for startup completion using the health endpoint



Loading models takes time, so sending requests immediately after starting with nohup will fail because the service isn't ready. Using sleep 10 as a workaround is unreliable—too short for slow machines and too long for fast ones.



The proper approach is to poll the service's health endpoint until it returns a 200 status. In this setup, the health endpoint is http://127.0.0.1:8770/health, so we poll it.




CODE
# Wait for the health endpoint to be ready before proceeding
until curl -sf http://127.0.0.1:8770/health >/dev/null; do
sleep 1
done
echo "backend ready"






curl -sf exits with a non-zero status on failure, so combining it with until allows you to wait until the service is ready. Waiting based on state, not a fixed delay, significantly improves the reliability of startup scripts.






TIP 5: Stop processes with pkill using pattern matching



For background processes without a saved PID, pkill with a command-line pattern is convenient for stopping them.




CODE
# Stop the inference service started with uvicorn
pkill -f "uvicorn server:app"






The -f option matches the entire command line, so including specific details like the port or app name in the pattern prevents unrelated processes from being affected. For more precision, save the PID during startup and target it directly.






Summary




  • macOS does not have setsid/timeout. Either install Homebrew's coreutils (gsetsid/gtimeout) or use standard tool alternatives

  • Use nohup ... & disown for background processes. Ignore SIGHUP and remove the job from the job table to prevent termination when the terminal is closed

  • Binary data in logs causes tr/grep to fail with Illegal byte sequence → Temporarily set LC_ALL=C to treat data as byte sequences

  • Instead of fixed sleep delays, poll the health endpoint with until curl -sf to wait based on state

  • Stop processes with pkill -f "specific pattern". Use a detailed pattern to avoid affecting unrelated processes

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
The Gemini desktop app is now available for Windows
1 Quelle
Windows 11 just dropped the tool ransomware abused, Microsoft says don’t restore WMIC
1 Quelle
Vorsicht: Android-Malware verschlüsselt Ihre Handys und nimmt heimlich Fotos auf