14. Termination Handling
14.1. Problem Statement
Previously, the HTTP server only responded to SIGKILL (kill -9), not to SIGTERM, because:
- The main server PID (root) would receive SIGTERM and set - RunServerto- false
- However, child PID (ResultProcessor, multiple ASProcessHandler PIDs) were not notified 
- Since child processes run as non-root, they are not automatically terminated on parent exit 
- This required manual cleanup with - kill -9for each process
14.2. Solution
Implemented proper termination handling where the main server process tracks all child PIDs and propagates SIGTERM signals to them.
14.3. How It Works
14.3.1. Process Hierarchy
Main Server (root, then drops privileges)
├── ResultProcessor (child process 1)
└── ASProcessHandler (multiple child processes, one per namespace interpreter)
14.3.2. Termination Flow
- User sends - kill -TERM <main_pid>or- pkill falcon-as
- Main server process receives SIGTERM 
- Signal handler - Server::terminate()is invoked
- Server::terminateChildren()sends SIGTERM to all registered child PIDs
- Each child process receives SIGTERM and their handlers set - RunServer = false
- All processes exit their main loops cleanly 
- Parent waits for children to exit (implicit via fork behavior) 
14.3.3. Key Design Decisions
- Static Members: - ChildPIDsis static to be accessible from the signal handler context
- Global Function: - registerChildPIDToServer()breaks Server, ASProcessHandler dependency
- PID Registration: Done in parent process immediately after fork succeeds 
- Signal Order: Children receive SIGTERM before parent exits 
14.4. Testing
A comprehensive test suite validates:
- Parent tracks child PIDs correctly 
- SIGTERM propagates from parent to all children 
- All processes exit cleanly without SIGKILL 
- Processes don’t terminate prematurely without SIGTERM 
14.5. Benefits
- Clean Shutdown: Server responds to standard SIGTERM signal 
- No Orphan Processes: All children are properly terminated 
- Resource Cleanup: Allows processes to clean up resources before exit 
- Standard Behavior: Follows Unix/Linux process management conventions 
- Systemd Compatible: Works correctly with systemd service management 
14.6. Usage
# start server
./usr/local/bin/falcon-as
# stop server (now works correctly)
pkill falcon-as
# or
kill -TERM <pid>