Search code examples
pythonpython-3.xsignalsmacos-monterey

How do I have a Python 3.11.5 process suspend itself on Monterey 12.6.8?


#!/usr/bin/python3

import os
import time

os.system('/bin/kill -19 ' + str(os.getpid()))
time.sleep(2)

On Linux this script returns immediately, suspended. On Mac this script waits for two seconds and exits without suspending itself.

What can I do to make the suspension behavior available on Mac?

TIA,


Solution

  • IPC Signal 19 seems to be not supported in MacOS. You can use -s SIGSTOP to suspend the process.

    
    import os
    import time
    
    os.system(f'/bin/kill -s SIGSTOP {os.getpid()}')
    time.sleep(2)