How Desktop Apps Handle Stale Processes Left Behind After Shutdown
Some desktop applications leave behind lingering processes after closing, causing port conflicts or duplicate instances on the next launch. A common fix involves writing the running process's PID and port to a file, then checking that file on startup to detect any leftover process. Because a process can exist without functioning correctly, the approach combines a PID liveness check with a socket connection test to distinguish true zombies from healthy instances. The PID check works differently across platforms: Unix systems use a zero-signal trick via os.kill(), while Windows relies on obtaining a process handle through OpenProcess(). If the stale process fails either check, it is forcibly terminated and its port file is cleared before the new instance starts.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in