Skip to main content

Changing priority of a running process from a AcuCobol program

  • January 19, 2012
  • 6 replies
  • 0 views

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.

6 replies

  • Author
  • Rocketeer
  • 19312 replies
  • January 19, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
This should be a fairly simple call to the Win32 API SetPriorityClass function. You need a handle to the process you want to set the priority of. If you want to set the priority of the current COBOL program, you can call GetProcess.

There is good documentation for calling Win32 API functions in the extend documentation set. It is probably best if I don't try to repeat that here!

  • Author
  • Rocketeer
  • 19312 replies
  • January 23, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
Thanks for your input, but I can't seem to make it work.
My code looks like this :

IDENTIFICATION DIVISION.
PROGRAM-ID. SETPRIORITY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.

01 WRK-FIELDS.
02 WRK-NUM-FIELDS.
03 SYS-PROCESS-ID PIC 9(7).
03 SYS-PRIORITY PIC 9(9) COMP-5.
03 WIN-PID PIC 9(9) COMP-5.
03 WIN-PID-HANDLE HANDLE.
03 WIN-RESULT PIC 9(9) COMP-5.

PROCEDURE DIVISION.
MAIN SECTION.
MAIN-ENTRY.

CALL "C$GETPID" GIVING SYS-PROCESS-ID.

SET ENVIRONMENT "DLL-CONVENTION" TO "1".

CALL "AdvAPI32.DLL".
CALL "Kernel32.DLL".

MOVE ZERO TO WIN-PID-HANDLE.
MOVE ZERO TO WIN-RESULT.

CALL "GetCurrentProcess" USING WIN-PID-HANDLE
GIVING WIN-RESULT.

MOVE SYS-PROCESS-ID TO WIN-PID-HANDLE.
MOVE 31 TO SYS-PRIORITY.
MOVE ZERO TO WIN-RESULT.

CALL "SetPriorityClass" USING WIN-PID-HANDLE
SYS-PRIORITY
GIVING WIN-RESULT.

CANCEL "AdvAPI32.DLL".
CANCEL "Kernel32.DLL".

SET ENVIRONMENT "DLL-CONVENTION" TO "0".

MAIN-EXIT.

STOP RUN.

  • Author
  • Rocketeer
  • 19312 replies
  • January 24, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
A couple of things.

First, SetPriorityClass takes a handle to the process, not the process-id. So calling C$GETPID is not necessary.

Next, GetCurrentProcess returns the process handle. It takes no arguments.

Next, SetPriorityClass doesn't set a particular priority, it sets a priority class. As such, the valid values for the second parameter are from a very limited set. And 31 is not one of those valid values.

Also, SetPriorityClass should be passed ints, so the arguments should be passed by value.

I modified the program to look like this, and when I run it in debug, and watch in Task Manager, I can see the priority change to High (which is what x#80 corresponds to).

       IDENTIFICATION DIVISION.
       PROGRAM-ID. SETPRIORITY.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.

       01 WRK-FIELDS.
       02 WRK-NUM-FIELDS.
       03 SYS-PRIORITY PIC 9(9) COMP-5.
       03 WIN-PID-HANDLE HANDLE.
       03 WIN-RESULT PIC S9(9) COMP-5.

       PROCEDURE DIVISION.
       MAIN SECTION.
       MAIN-ENTRY.

           SET ENVIRONMENT "DLL-CONVENTION" TO "1".

           CALL "AdvAPI32.DLL".
           CALL "Kernel32.DLL".

           MOVE ZERO TO WIN-PID-HANDLE.
           MOVE ZERO TO WIN-RESULT.

           CALL "GetCurrentProcess" GIVING WIN-PID-HANDLE.

           MOVE x#80 TO SYS-PRIORITY.
           MOVE ZERO TO WIN-RESULT.

           CALL "SetPriorityClass" USING by value
                 WIN-PID-HANDLE SYS-PRIORITY
           GIVING WIN-RESULT.

           CANCEL "AdvAPI32.DLL".
           CANCEL "Kernel32.DLL".

           SET ENVIRONMENT "DLL-CONVENTION" TO "0".

       MAIN-EXIT.

           STOP RUN.


I hope this helps.

  • Author
  • Rocketeer
  • 19312 replies
  • January 24, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
Thanks a lot - that did help :-)

Regards
Steen

  • Author
  • Rocketeer
  • 19312 replies
  • January 24, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
Thanks a lot - that did help :-)

Regards
Steen

  • Author
  • Rocketeer
  • 19312 replies
  • January 24, 2012

[Migrated content. Thread originally posted on 17 January 2012]

Hi :-)
Have anyone tried to change the priority of a running process from within AcuCobol program ? I've read that it can be done from VB with a call to SetPriorityClass, but I would like to do the same call from within AcuCobol.
Any help would be appreciated.
Thanks a lot - that did help :-)

Regards
Steen