Sample Header Ad - 728x90

Suspend and then resume a process in python script - Linux

0 votes
1 answer
5330 views
I am trying to see if there is a way I can suspend and then resume a process in a Python script. I get the process pid using os.getpid() and then I suspend the process using suspend(). Is there a way to resume the process without having to manually type fg in a shell? Here is my code:
-python
#!/usr/bin/env python
import time
import psutil
import os

sm_pid = os.getpid()
p = psutil.Process(sm_pid)

print "Going to suspend"
p.suspend()

time.sleep(5)
p.resume()

print "process resumed"
Asked by hama_ROW (1 rep)
Nov 27, 2018, 12:45 AM
Last activity: Jan 16, 2025, 03:14 PM