Build process tree for macOS
Fix for issue: https://github.com/pkrumins/node-tree-kill/issues/43
Issue: When using tree-kill on macOS within applications that frequently restart (such as NestJS in watch mode), the module fails with a spawn EBADF error. The error occurs in the buildProcessTree function when attempting to spawn child processes to get the process tree. This appears to be due to file descriptor handling issues specific to macOS.
The issue appears to be related to how spawn handles file descriptors on macOS when used recursively in rapid succession. The current implementation uses spawn to build the process tree, which can lead to file descriptor exhaustion or race conditions when processes are frequently being killed and restarted.
Fix
Uses execSync with proper timeout and error handling specifically for macOS to avoid the EBADF issues. Adds a new function buildProcessTreeMacOS for macOS or darwin platform