PxPlus User Forum

Twitter Twitter Twitter

Author Topic: Does PID Exist  (Read 1410 times)

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 174
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Does PID Exist
« on: May 20, 2021, 09:41:07 AM »
Hi All, i've done this with various dos utilities and powershell but does anyone have / know of some function/black box to pass in a Process ID in Windows and return a boolean if process exists.

Allen Miglore

  • Silver Member
  • ***
  • Posts: 38
    • View Profile
    • UnForm
Re: Does PID Exist
« Reply #1 on: May 20, 2021, 09:47:27 AM »
The sys() function can be used.

if sys(pid)=0 then exists=1


Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 174
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Re: Does PID Exist
« Reply #2 on: May 20, 2021, 09:55:35 AM »
Hi Allen, i dont know if this is a Unix/Linux thing but in windows every time I do that it returns -1 whether it exists or doesnt.

James Zukowski

  • Diamond Member
  • *****
  • Posts: 296
    • View Profile
Re: Does PID Exist
« Reply #3 on: May 20, 2021, 10:24:02 AM »
According to the documentation:
"The SYS function can be used to determine the state [of] another process on the system. [T]he SYS function will return zero if the specified process is still executing or -1 if the process cannot be found ..."

James Zukowski
Sr. Developer - J&E

BRAND>SAFWAY
Brand Industrial Services

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Does PID Exist
« Reply #4 on: May 20, 2021, 10:24:57 AM »
Jeff,

I just tried this myself on Windows 10 and it worked.

I brought up the Windows Task Manager, asked for "More Details" so the the PID would show, then tried SYS(nnn) with a number of the PIDs.  It always seemed to return 0 when the process existed and -1 if it didn't.

If that is not working for you, let us know what version of Windows are you using in case Microsoft has changed something.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 174
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Re: Does PID Exist
« Reply #5 on: May 20, 2021, 10:36:40 AM »
Hi All, it returned 0 for my process id 32212
and it works for a user i have called background that just runs a pxplus process all day.
I am a System Administrator on the machine.
The OS is Windows Server 2016 Standard
I cannot get it to work for any other user.

-:? sys(32212)
 0
-:? sys(2728)
-1
-:? sys(25868)
-1
-:? sys(32212)
 0

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 174
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Re: Does PID Exist
« Reply #6 on: May 20, 2021, 10:44:24 AM »
i just tried it on a 2012 server on several pxplus processes..it worked on  3 of them. i'm checking to make sure pid's are still out there after i execute sys(pid)....i'll go back to my old way for now.

Mike King

  • Diamond Member
  • *****
  • Posts: 3810
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: Does PID Exist
« Reply #7 on: May 20, 2021, 10:57:02 AM »
Well checking on the status of other user processes is considered an admin function so my guess is Windows denies our get status request. 

Windows has a lot of built-in security, mostly good, but some that can get in the way. 

You might also try something like this:

found=0
SELECT RECORD r$ FROM "<tasklist /FI ""PID eq 3996"" /NH" WHERE POS("3996"=r$)
  found = 1
NEXT RECORD
PRINT found


Just replace 3996 with the PID you are looking for.

Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Jeffrey Ferreira

  • Diamond Member
  • *****
  • Posts: 174
  • I must have taken a wrong turn at Albuquerque.
    • View Profile
Re: Does PID Exist
« Reply #8 on: May 20, 2021, 10:59:08 AM »
Mike,

i just did something like that with tasklist  but i used an interim text file.
that is much better...that will work perfect...
thank you !!!!
jeff