Find and Kill PID of Process

Seven Stars

Find and Kill PID of Process

I have developed a job in Talend studio that runs a windows Batch file using tSystem component.

 

The batch file kicks off a R script. I can see this R process in Windows task manager once the batch is executed.

 

At times when I have to kill the job from Studio or even from TMC the R script kicked off by windows batch keeps running even though the parent job has been killed.

 

Is there a way to find the PID from within Talend Studio and kill the R process as part of a job flow. I have a timeout context variable, which if not set after 1 hour will be used in tjava to kill the job, however the problem is that even if the job is killed - the R script will keep running - unless I can obtain the PID of this within the job flow and execute a taskkill command as part of the job flow.

 

I can run the following command to kill the executable:

taskkill /IM Rscript.exe /F

 

However the problem with this approach is that there may be other jobs running in parallel that may also be executing scripts using Rscript.exe .

 

How can I cleanly identify the PID and then kill it as part of the flow.

 

Thanks

Tags (1)
Employee

Re: Find and Kill PID of Process

Hi,

 

    You will have to list the processed ids based on your user name and from that process id, pick the id which is having R script in the name.

 

    If you are looking for different options available to see the task list, please refer the below link.

 

https://jpsoft.com/help/tasklist.htm

 

    Once the Windows script is created, you can call them from tSystem component like any other command. Before initiating the kill command, please double check the process ids by printing them in the test flows.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

Seven Stars

Re: Find and Kill PID of Process

What if you have multiple processes running but you want to kill only one of them. For example I have multiple jobs that run an executable via tsystem and I want to kill the executable for only one job. How can I identify which executable maps to which Talend flow?
Employee

Re: Find and Kill PID of Process

Hi,

 

    Could you please try the details given in below link?

 

https://serverfault.com/questions/126502/how-to-get-own-process-pid-from-the-command-prompt-in-windo...

 

     Personally I have not tried it but it seems to have up votes.

 

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved :-)

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 1

Learn how to do cool things with Context Variables

Blog

Migrate Data from one Database to another with one Job using the Dynamic Schema

Find out how to migrate from one database to another using the Dynamic schema

Blog

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog