PxPlus User Forum
Main Board => Discussions => Programming => Topic started by: Jeffrey Ferreira 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.
-
The sys() function can be used.
if sys(pid)=0 then exists=1
-
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.
-
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 ..."
-
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.
-
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
-
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.
-
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,
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