Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to kill a work process within a custom program (batch)

QBY_Stefan
Explorer
0 Likes
4,323

Hi guys,

using SCN for years and finally took the time to register.

Here's the situation: We have a program in our producitve system that starts parallel processes while running.

Sometimes (the cause is not yet determined) one process just runs longer with no attempt to stop. The main process is captured at a WAIT UNTIL command. We basically wait a defined time, then we want to automatically EXIT the program. Let's just say we don't want long runs.

Now: We want that one parallel process to be killed. This is why because our main program is running all day in a loop and cant be restarted, if one parallel process is still running. At the moment we are killing the process in SM50 manually. We want that to be done automatically within the main program.

I found some functions TH_* like TH_SYSTEMWIDE_WPINFO which provides all wps from all application servers. There I can see my process, but how can I kill it and do I have to change application server as there are up to 6 different ones where the parallel process might be running (because of parallelization the main programm can be running on a different application server as the parallel process)?

Many thanks for your ideas!

Regards

Stefan

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,730

There is a system command to kill a process :

CONSTANTS: opcode_wp_stop TYPE x VALUE 2. " or INCLUDE TSKHINCL
CALL 'ThWpInfo' ID 'OPCODE' FIELD opcode_wp_stop
                ID 'PID' FIELD pid.

or use TH_STOP_WP FM.


Regards,

Raymond

7 REPLIES 7
Read only

Former Member
0 Likes
2,730

Stefan,

We have a similar process in our system. I dont know how to kill an existing process but what we did was to code a wait until <logical expression> along with a <time frame>.

This way the main program will only be allowed to run for a certain # of seconds irrespective of the logical expression on the wait statement. If the time is up the main program continues with its execution.

WAIT UNTIL log_exp [UP TO sec SECONDS].

Hope this helps with atleast one part of your solution.

Thanks,

Vikram.M

Read only

Former Member
0 Likes
2,730

Hi Stefan,

We do get all the details of the processes running through the FM 'TH_SYSTEMWIDE_WPINFO'.

Based on the conditions we can transfer the details to a file (killproc.bat) on the application server through an scheduled abap program.

abap program - condition example:

IF WA-WP_TYP = 'DIA' AND WA-WP_STATUS = 'Running' AND WA-WP_ELTIME GT 5000.
       CONCATENATE 'taskkill' '/pid ' wa-wp_pid '/F' into str SEPARATED BY space.

       transfer str to w_dataset1.

ENDIF.


Finally we have to create schedules on the application server to run this file killproc.bat


This file has command taskkill with pid number.


example: taskkill /pid 1836 /F


I do hope you go the idea.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
2,731

There is a system command to kill a process :

CONSTANTS: opcode_wp_stop TYPE x VALUE 2. " or INCLUDE TSKHINCL
CALL 'ThWpInfo' ID 'OPCODE' FIELD opcode_wp_stop
                ID 'PID' FIELD pid.

or use TH_STOP_WP FM.


Regards,

Raymond

Read only

0 Likes
2,730

Hi Raymond,

FM TH_STOP_WP is exactly what we need. I didn't think of system commands before.

If we use this one, I have to be on the same server as the process with the pid, right?

If the program is currently running on a different server though, how can I switch to the correct server within the program?

Thank you!

Regards

Stefan

Read only

0 Likes
2,730

Debug SM51 on a multi-app-server system, and you should be able to figure it out.

Read only

0 Likes
2,730

Just to complete this topic:

Switching server is done in FM TH_REMOTE_TRANSACTION.



CALL FUNCTION 'TH_REMOTE_TRANSACTION'
           EXPORTING
               dest   = <your server>
               tcode = space.


This can be found in program rsm51000_alv in routine sm51_user_cmd.


Thanks!
Regards

Stefan

Read only

0 Likes
2,730

Hi Mr. Mathew & Mr. Raymond,

using the fm 'TH_REMOTE_TRANSACTION' we get the list of PIDs running on other application servers.


If we delete the process  using fm 'ThWpInfo' or TH_STOP_WP then will it delete on the other application server?