Suspend and then resume a process in python scrip - Linux

The name of the pictureThe name of the pictureThe name of the pictureClash 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"









share|improve this question



















  • 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














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"









share|improve this question



















  • 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












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"









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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












  • 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










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.






share|improve this answer




















    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    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

























    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.






    share|improve this answer
























      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.






      share|improve this answer






















        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.






        share|improve this answer












        You could start an asynchronous process
        that sleeps for five seconds (or whatever)
        and then sends a SIGCONT signal to the main process.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 at 1:18









        Scott

        6,77642650




        6,77642650



























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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






            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay