How to kill child processes spawned by Windows task scheduler? Announcing the arrival of...

What is the meaning of the new sigil in Game of Thrones Season 8 intro?

How discoverable are IPv6 addresses and AAAA names by potential attackers?

Echoing a tail command produces unexpected output?

Coloring maths inside a tcolorbox

When a candle burns, why does the top of wick glow if bottom of flame is hottest?

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

How does the particle を relate to the verb 行く in the structure「A を + B に行く」?

Fundamental Solution of the Pell Equation

How to find all the available tools in mac terminal?

Why is my conclusion inconsistent with the van't Hoff equation?

How widely used is the term Treppenwitz? Is it something that most Germans know?

How can I make names more distinctive without making them longer?

Can an alien society believe that their star system is the universe?

Using et al. for a last / senior author rather than for a first author

Short Story with Cinderella as a Voo-doo Witch

What's the meaning of 間時肆拾貳 at a car parking sign

Why was the term "discrete" used in discrete logarithm?

Why aren't air breathing engines used as small first stages

porting install scripts : can rpm replace apt?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

What is Wonderstone and are there any references to it pre-1982?

Identifying polygons that intersect with another layer using QGIS?

Why didn't this character "real die" when they blew their stack out in Altered Carbon?

Identify plant with long narrow paired leaves and reddish stems



How to kill child processes spawned by Windows task scheduler?



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)When a Python process is killed on OS X, why doesn't it kill the child processes?kill process windows using taskkillHow to kill a task that is “lacking an instance”?Tell Task Scheduler how to end a taskWindows - Kill All Non-Essential Running ProcessesWindows 10: Processes stuck in “Suspended” stateTask Scheduler permission issues on Network DriveIncipient instability in Microsoft Task Scheduler?Windows task scheduler does not kill child processTask Scheduler Tasks Running at the Same Time





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I have a python script that runs forever but I'd like to restart every day just in case it gets into a bad state, gets shut down, etc. I'm scheduling it daily with task scheduler, which is fine.



The problem is that my script spawns other processes, and those child processes don't get killed when the task is stopped (ex: when I manually end it, or a new instance of the task runs). The main script is killed, but the child processes are not. I have to kill them manually through task manager. If I run my main script on the command line, instead of through task scheduler, closing the console kills all child processes, as expected.



I tried running the task with and without "highest privileges", "if the task does not end when requested, force it to stop", "if the task is already running, stop the existing instance", etc. I've tried running taskkill as the first action of the task. I've tried everything I can think of. I'm running the task as myself, and I'm administrator.



The problem seems to be that the child processes spawned by tasks are access protected. I've tried taskkill, pskill, python scripts like this:



import psutil
for process in psutil.process_iter():
cmdline = process.cmdline()
if "myscript.py" in cmdline:
process.terminate()


I always get an access denied error. Example from taskkill:



c:>taskkill /f /t /im python.exe
ERROR: The process with PID 14436 (child process of PID 7928) could not be terminated.
Reason: Access is denied.
ERROR: The process with PID 7928 (child process of PID 14324) could not be terminated.
Reason: Access is denied.
...


Hell, I even tried having my main python script kill its own child process when a termination event comes in, but I don't even get that event with task scheduler, with or without force kill! Again, on a normal command line run, I get termination events as expected. But thwarted by task scheduler once again.



This is also very easy to reproduce with a one line batch file that runs a python script. If task scheduler runs the batch file, and you end the task, the python script will not be killed when the task is ended.



Any idea why child processes spawned by task scheduler tasks are not killed and how to work around it?



Thanks!










share|improve this question





























    1















    I have a python script that runs forever but I'd like to restart every day just in case it gets into a bad state, gets shut down, etc. I'm scheduling it daily with task scheduler, which is fine.



    The problem is that my script spawns other processes, and those child processes don't get killed when the task is stopped (ex: when I manually end it, or a new instance of the task runs). The main script is killed, but the child processes are not. I have to kill them manually through task manager. If I run my main script on the command line, instead of through task scheduler, closing the console kills all child processes, as expected.



    I tried running the task with and without "highest privileges", "if the task does not end when requested, force it to stop", "if the task is already running, stop the existing instance", etc. I've tried running taskkill as the first action of the task. I've tried everything I can think of. I'm running the task as myself, and I'm administrator.



    The problem seems to be that the child processes spawned by tasks are access protected. I've tried taskkill, pskill, python scripts like this:



    import psutil
    for process in psutil.process_iter():
    cmdline = process.cmdline()
    if "myscript.py" in cmdline:
    process.terminate()


    I always get an access denied error. Example from taskkill:



    c:>taskkill /f /t /im python.exe
    ERROR: The process with PID 14436 (child process of PID 7928) could not be terminated.
    Reason: Access is denied.
    ERROR: The process with PID 7928 (child process of PID 14324) could not be terminated.
    Reason: Access is denied.
    ...


    Hell, I even tried having my main python script kill its own child process when a termination event comes in, but I don't even get that event with task scheduler, with or without force kill! Again, on a normal command line run, I get termination events as expected. But thwarted by task scheduler once again.



    This is also very easy to reproduce with a one line batch file that runs a python script. If task scheduler runs the batch file, and you end the task, the python script will not be killed when the task is ended.



    Any idea why child processes spawned by task scheduler tasks are not killed and how to work around it?



    Thanks!










    share|improve this question

























      1












      1








      1








      I have a python script that runs forever but I'd like to restart every day just in case it gets into a bad state, gets shut down, etc. I'm scheduling it daily with task scheduler, which is fine.



      The problem is that my script spawns other processes, and those child processes don't get killed when the task is stopped (ex: when I manually end it, or a new instance of the task runs). The main script is killed, but the child processes are not. I have to kill them manually through task manager. If I run my main script on the command line, instead of through task scheduler, closing the console kills all child processes, as expected.



      I tried running the task with and without "highest privileges", "if the task does not end when requested, force it to stop", "if the task is already running, stop the existing instance", etc. I've tried running taskkill as the first action of the task. I've tried everything I can think of. I'm running the task as myself, and I'm administrator.



      The problem seems to be that the child processes spawned by tasks are access protected. I've tried taskkill, pskill, python scripts like this:



      import psutil
      for process in psutil.process_iter():
      cmdline = process.cmdline()
      if "myscript.py" in cmdline:
      process.terminate()


      I always get an access denied error. Example from taskkill:



      c:>taskkill /f /t /im python.exe
      ERROR: The process with PID 14436 (child process of PID 7928) could not be terminated.
      Reason: Access is denied.
      ERROR: The process with PID 7928 (child process of PID 14324) could not be terminated.
      Reason: Access is denied.
      ...


      Hell, I even tried having my main python script kill its own child process when a termination event comes in, but I don't even get that event with task scheduler, with or without force kill! Again, on a normal command line run, I get termination events as expected. But thwarted by task scheduler once again.



      This is also very easy to reproduce with a one line batch file that runs a python script. If task scheduler runs the batch file, and you end the task, the python script will not be killed when the task is ended.



      Any idea why child processes spawned by task scheduler tasks are not killed and how to work around it?



      Thanks!










      share|improve this question














      I have a python script that runs forever but I'd like to restart every day just in case it gets into a bad state, gets shut down, etc. I'm scheduling it daily with task scheduler, which is fine.



      The problem is that my script spawns other processes, and those child processes don't get killed when the task is stopped (ex: when I manually end it, or a new instance of the task runs). The main script is killed, but the child processes are not. I have to kill them manually through task manager. If I run my main script on the command line, instead of through task scheduler, closing the console kills all child processes, as expected.



      I tried running the task with and without "highest privileges", "if the task does not end when requested, force it to stop", "if the task is already running, stop the existing instance", etc. I've tried running taskkill as the first action of the task. I've tried everything I can think of. I'm running the task as myself, and I'm administrator.



      The problem seems to be that the child processes spawned by tasks are access protected. I've tried taskkill, pskill, python scripts like this:



      import psutil
      for process in psutil.process_iter():
      cmdline = process.cmdline()
      if "myscript.py" in cmdline:
      process.terminate()


      I always get an access denied error. Example from taskkill:



      c:>taskkill /f /t /im python.exe
      ERROR: The process with PID 14436 (child process of PID 7928) could not be terminated.
      Reason: Access is denied.
      ERROR: The process with PID 7928 (child process of PID 14324) could not be terminated.
      Reason: Access is denied.
      ...


      Hell, I even tried having my main python script kill its own child process when a termination event comes in, but I don't even get that event with task scheduler, with or without force kill! Again, on a normal command line run, I get termination events as expected. But thwarted by task scheduler once again.



      This is also very easy to reproduce with a one line batch file that runs a python script. If task scheduler runs the batch file, and you end the task, the python script will not be killed when the task is ended.



      Any idea why child processes spawned by task scheduler tasks are not killed and how to work around it?



      Thanks!







      windows python scheduled-tasks tasks






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 18 hours ago









      SteveSteve

      1362




      1362






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "3"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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%2fsuperuser.com%2fquestions%2f1425991%2fhow-to-kill-child-processes-spawned-by-windows-task-scheduler%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Super User!


          • 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%2fsuperuser.com%2fquestions%2f1425991%2fhow-to-kill-child-processes-spawned-by-windows-task-scheduler%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

          Why not use the yoke to control yaw, as well as pitch and roll? Announcing the arrival of...

          Couldn't open a raw socket. Error: Permission denied (13) (nmap)Is it possible to run networking commands...

          VNC viewer RFB protocol error: bad desktop size 0x0I Cannot Type the Key 'd' (lowercase) in VNC Viewer...