Suspend and then resume a process in python scrip - Linux
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
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:
#!/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"
linux process python
add a comment |
up vote
0
down vote
favorite
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:
#!/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"
linux process python
1
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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:
#!/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"
linux process python
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:
#!/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"
linux process python
linux process python
edited Nov 27 at 1:15
Rui F Ribeiro
38.4k1477127
38.4k1477127
asked Nov 27 at 0:45
hama_ROW
11
11
1
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46
add a comment |
1
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46
1
1
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You could start an asynchronous process
that sleeps for five seconds (or whatever)
and then sends a SIGCONT
signal to the main process.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You could start an asynchronous process
that sleeps for five seconds (or whatever)
and then sends a SIGCONT
signal to the main process.
add a comment |
up vote
0
down vote
You could start an asynchronous process
that sleeps for five seconds (or whatever)
and then sends a SIGCONT
signal to the main process.
add a comment |
up vote
0
down vote
up vote
0
down vote
You could start an asynchronous process
that sleeps for five seconds (or whatever)
and then sends a SIGCONT
signal to the main process.
You could start an asynchronous process
that sleeps for five seconds (or whatever)
and then sends a SIGCONT
signal to the main process.
answered Nov 27 at 1:18
Scott
6,77642650
6,77642650
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f484334%2fsuspend-and-then-resume-a-process-in-python-scrip-linux%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What are you trying to accomplish with a suspension that you can't accomplish with a simple sleep?
– BowlOfRed
Nov 27 at 0:58
The sleep is just a placeholder here. I'm trying to "pause" a process and then resume it after receiving a user input through a GUI
– hama_ROW
Nov 28 at 16:42
Suspend probably isn't the right way (because the process can't wake itself up). Normally GUIs have a main loop that will accept input signals and execute callbacks, pausing when none are available (often via select()). I would suspect the specifics of the GUI might matter here.
– BowlOfRed
Nov 28 at 16:51
My GUI is executing callbacks from a main loop but it is running on a separate thread. I'm trying to pause the process on the main thread from the GUI thread and then resume it by sending a command again from the GUI thread.
– hama_ROW
Nov 28 at 17:16
Are these threads separate processes as well? Suspension is per-process, not per-thread. You can't suspend only part of a process. It's possible your question would be better handled by python folks in stackoverflow rather than as a generic unix question.
– BowlOfRed
Nov 28 at 17:46