in reply to Re^3: Kill a serial of jobs with a button click in Perl/TK
in thread Kill a serial of jobs with a button click in Perl/TK

kill, AFAIK, only works on running processes.

If you think of the kill(2) system call, this is wrong. You can send signals to all processes, not only those that are currently running. (That limitation would make signals quite useless on all single-core systems, where only one process can be running at any point of time. You could only send signals to the own process.)

If they are executing sequentially, only one of them is "running", the rest is ... waiting? queued?

Tk::ExecuteCommand creates "background" processes, i.e. the processes are started and execute_command() returns before the process just started terminates. If you issue several execute_command() calls (for different instances of Tk::ExecuteCommand), you create several processes, running in parallel.

Update: I'm not quite sure about the previous paragraph. execute_command() calls several Tk methods that allow Tk to continue working, but execute_command() returns only after it considers the command to have finished ($self->{'-finish'} changes). Tk continues to handle events, so by clicking another button, another execute_command() may run.

(what I want to say is: they probably are not "processes" yet)

This is an instance of Tk::ExecuteCommand where either execute_command() has not yet been called or the executed child process has already terminated. There seems to be no method that can be used to test if the process is still running, unfortunately. The documentation does not detail what happens when a process terminates or when the methods get_status() and kill_command() are called before execute_command().

Looking at the source code gives some hints:

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^5: Kill a serial of jobs with a button click in Perl/TK
by soonix (Chancellor) on May 25, 2015 at 11:33 UTC

    Yes, I was thinking of the kill kommand. The OP stated that the jobs are "triggered successfully one after another", which led me to the assumption that they are somehow put into a queue, and Tk::ExecuteCommand of the second job is done only after the first has completed. At least this would be an explanation for the reported behaviour.

    I think we need more info (source) from Janish to be able to help.

      Thanks Soonix, your guest is right, I only aware that yes, how am I expect the command to kill a job which is still in-queue and not active, that is ridiculous. Thanks for your explanation, I'll need to re-structure my code to run them in-parallel instead.

Re^5: Kill a serial of jobs with a button click in Perl/TK
by Janish (Sexton) on May 26, 2015 at 06:02 UTC

    Thank you so much Alexander, you detailed explanation helps me understand more on each the command. Yes, you're right, my so-call jobs that I plan to kill are actually in-queue and yet to process, that explain why my codes just triggered kill process on the first job which is only active at that moment. Thank you so much, I'll have to restructure my code.