Kill Scheduled Job or Sub Job in command prompt

Get help for specific problems
Posts: 5
Joined: 19 Aug 2013

ya127704624

Hello,

I have many scheduled file synchronize jobs run in parallel, and each job has multiple source and destination pairs (sub jobs). Is it able to:
1) Kill a specific sub job in command prompt ?
2) Kill a specific job in command prompt ?
Thanks.

Cheers,
Daisy
Posts: 28
Joined: 6 Aug 2013

petrovski80

1) What you call a 'sub job' (folder pair) isn't spawned as a separate process. A FFS job runs as a single process which then processes the folder pairs. So no.

2) Yes, you can use taskkill /PID <ID> for this.

Out of curiosity, what are you trying to accomplish? Because taskkill can kill processes by ID (multiple instances of FFS will have the same image name), the trick is to link the PIDs to the jobs.
Posts: 5
Joined: 19 Aug 2013

ya127704624

multiple instances of FFS will have the same image name <-- How can I get the PID for the process I want to kill then?
Posts: 28
Joined: 6 Aug 2013

petrovski80

It depends on how you start your FFS batch jobs. If you use a Windows batch file, you could store the PID of each new instance you start like this:

http://stackoverflow.com/questions/9486960/windows-batch-scripting-get-pid-of-just-started-process

But again, what is the underlying question here? Why would you want to abort FFS jobs? Depending on the answer, there might be other (easier) ways to accomplish your goal.
Posts: 5
Joined: 19 Aug 2013

ya127704624

Now I have batch files to trigger the FFS jobs. The batch files are executed by task scheduler in scheduled time. If the job runs longer than a specific time (i.e. 2 hours), it is needed to be terminated. Can you suggest a simple way to terminate the FFS job automatically? Thanks.
Posts: 28
Joined: 6 Aug 2013

petrovski80

Yes I'd use the Windows task scheduler for this. The settings tab of a task has the option to stop a task if it's running for longer than <n> hours/days:

[404, Invalid URL: http://image.bayimg.com/30daba79b3c0dad1f6aa31329b415f1a20b794e7.jpg]

Update: correction, this won't work. It would kill the running batch script, but since that already started FFS that process continues to run.
Posts: 5
Joined: 19 Aug 2013

ya127704624

yes...any other ways to retrieve the purpose ?
Posts: 28
Joined: 6 Aug 2013

petrovski80

a) You could not use a batch script to start the FFS batch job. Just call the freefilesync.exe directly and pass the path to the .ffs_batch as an argument. Then the task scheduler option will work correctly.

b) Handle the desired timeout in a script using a counter. Windows batch scripting does not support sleep or wait methods. There are workarounds, but not recommended for longer timeouts. So I'd recommend using a more advanced scripting engine such as Powershell or AutoIt.
Posts: 5
Joined: 19 Aug 2013

ya127704624

Tried method a, but the task scheduler only killed FreeFileSync.exe (without killing FreeFileSync_x64.exe), so the file sync job was keep running.
Posts: 28
Joined: 6 Aug 2013

petrovski80

Hm. You could of course create a new scheduled task that runs a batch script that kills the process FreeFileSync_x64.exe if it's running, and schedule that task to be executed 2 hours after the start of the FFS batch job.

That will kill all instances of FreeFileSync_x64.exe however, and you've indicated you run several jobs in parallel. So not a good option for you.

In your situation, your best option is to use an advanced script I think.