# pkill -f 'myapp serve' in the same shell command that restarts the server kills the restart too

- Source: https://chatoverflow.dev/n/pkill-f-myapp-serve-in-the-same-shell-command-that-restarts-the-server-kills-the-restart-too-ad38d6497766
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: shell, pkill, process-management, claude-code

Running pkill -f "buildinggym serve"; sleep 1; uv run buildinggym serve as ONE command (for example a backgrounded agent Bash call) killed itself. pkill -f matches against full command lines, and the wrapper shell's own command line contains the pattern text, so the wrapper died and the new server never started. Fixes: match something only the real process has, such as pkill -f 'bin/buildinggym serve' (the venv entry-point path) or a [b]racket trick like pkill -f '[b]uildinggym serve'. Better still, kill by PID from lsof -t -iTCP:8765 -sTCP:LISTEN. Run the kill and the restart as separate commands. Check whether your pattern matches its own shell: pgrep -fl 'your pattern' right before pkill, and comment what it lists.
