Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

@PID weirdness

Jul
177
1
This one has me beat, so even though I guess that the version of TCMD that I'm running is out of support, I'm going to try posing this teaser here.

I have a batch file that I use to invoke Skyrim and tweak which control mappings get passed to the game for each user (since that file is stored within the Steam program files area rather than in the user's documents like the rest of the configurable files). When I wrote it I'd forgotten (or perhaps never knew) about PROCESSMONITOR, but I cannot figure a ready way of replacing what I'm doing with that command anyway. Once the batch code has figured out that the game has started running (it cannot just use START /WAIT because of the game launcher and/or Steam, both of which result in START returning before the game executable is running) it saves the process ID and runs the following loop:

Code:
 SET SKYRIM_PID=%@PID["TESV.EXE"]
...
SET LOOP_COUNT=0
DO WHILE %SKYRIM_PID NE 0
   SET LOOP_COUNT=%@INC[LOOP_COUNT]
   DELAY 5
   SET LATEST_PID=%@PID["TESV.EXE"]
   IFF %LATEST_PID EQ 0 THEN
      LEAVE
   ENDIFF
   IFF %LATEST_PID NE %SKYRIM_PID THEN
      SET OUTMSG=TESV executable PID has changed from %SKYRIM_PID to %LATEST_PID
      ECHO %OUTMSG (%@PIDCOMMAND[%LATEST_PID]) >>D:\Users\Public\Documents\logs\%@NAME[%_BATCHNAME].log
      *TASKLIST /O /N >>D:\Users\Public\Documents\logs\%@NAME[%_BATCHNAME].log
      SET SKYRIM_PID=%LATEST_PID
   ENDIFF
REM We report once an hour if the executable is still running
   IFF %@EVAL[LOOP_COUNT MOD 720] EQ 0 THEN
      SET OUTMSG=TESV executable [%SKYRIM_PID] still running after %LOOP_COUNT checks
      ECHO %OUTMSG >>D:\Users\Public\Documents\logs\%@NAME[%_BATCHNAME].log
   ENDIFF
ENDDO
ECHO TESV ended at %_time on %_date >>D:\Users\Public\Documents\logs\%@NAME[%_BATCHNAME].log
This is all fine and dandy, and essentially does the necessary, but often when the executable ends @PID returns a value for a different process that seems to have no association to TESV.EXE (best as I can tell). This can introduce a delay of several minutes before the checking loop finally ends, which is causing one or two headaches (related to what happens after the loop ends) as well as being rather frustrating. Here is an extract of the log entries for one such instance:

Code:
Starting TESV at 19:27:18 on 12/12/11
TESV executable visible after 0 ticks (5204: "c:\program files (x86)\steam\steamapps\common\skyrim\TESV.exe")
0 [System Process]
4 System
348 smss
400 TASKENGINEWINDOWCLASS taskeng TaskEng - Task Scheduler Engine Process
416 nvvsvc
428 avgchsva
612 Afx:00080000:0 vdDaemon razervdDaemon
648 svchost
660 svchost
696 csrss
784 wininit
800 csrss
844 services
860 lsass
868 lsm
896 winlogon
988 #32770 HsMgr ComHookMonitor
1008 svchost
1036 svchost
1068 svchost
1236 svchost
1332 TCPSVCS
1360 svchost
1480 svchost
1568 spoolsv
1584 GDI+ Hook Window Class LWEMon Logitech Wingman Event Monitor
1608 svchost
1636 svchost
1648 UxdService NvXDSync UxdService
1668 NVSVC64.DLL nvvsvc NvSvc
1760 avgfws
1856 avgwdsvc
1892 k9filter
1900 svchost
1924 CTDevSrv
1936 AVGIDSAgent
1992 NBService
2132 jusched
2288 SearchProtocolHost
2404 avgam
2420 avgnsa
2484 GDI+ Hook Window Class AsusAudioCenter Xonar DS Audio Center
2660 WUDFHost
2828 HWSW_SQMSessionWindow itype keyboard
3024 #32770 HsMgr64 ComHookMonitor
3032 WorkerW ImpulseNow GDI+ Window
3064 .NET-BroadcastEventWindow.2.0. IAStorIcon GDI+ Window
3084 audiodg
3128 ShrAliasWindowClass ShrAlias ShrAliasWindow
3204 conhost
3464 caller64
3468 Afx:00400000:0 razerhid razerAbyssushid
3472 IconoidHidden iconoid64 Iconoid Hidden Window
3608 CicLoaderWndClass taskhost Task Host Window
3708 Dwm dwm DWM Notification Window
3716 Samsung PanelMgr SSMMgr Samsung PanelMgr
3748 Progman explorer Program Manager
3776 dpupdchk
3888 AvgWndClass_Tray avgtray AvgTrayMainWnd
3996 avgcsrva
4016 GDI+ Hook Window Class sidebar AVG
4020 Usb30Monitor nusb3mon USB 3.0 Monitor
4336 Afx:400000:0 razertra RazerAbyssusTrayIcon
4348 nvtray
4496 SearchIndexer
4652 daemonu
4664 #32770 RealTemp 36øC 37øC 38øC 37øC
4696 AVGIDSMonitor
4728 IAStorDataMgrSvc
4772 Razer On-the-Fly Sensitivity A razerofa Razer On-the-Fly Sensitivity Adjustment
4784 __ipw_socket_wnd__ tcmd TC 12.11 - TCC Prompt
4920 tooltips_class32 procexp64 Process Explorer - Sysinternals: www.sysinternals.com [Nemesis\NemesisAdmin]
4968 wmpnetwk
5132 KeditFrame32 KEDITW32 KEDIT - [D:\programs\BAT\skyrim_go.btm]
5156 __ipw_socket_wnd__ tcc TCC Prompt
5204 DIEmWin TESV Skyrim
5232 GameOverlayUI
5476 avgrsa
5508 avgcsrva
6400 USurface_39545583 Steam Screenshot Manager
6404 conhost
6908 SteamService
7316 SearchFilterHost
7488* __ipw_socket_wnd__ tcc Skyrim Go
TESV executable PID has changed from 5204 to 1164 ()
0 [System Process]
4 System
348 smss
400 TASKENGINEWINDOWCLASS taskeng TaskEng - Task Scheduler Engine Process
416 nvvsvc
428 avgchsva
612 Afx:00080000:0 vdDaemon razervdDaemon
648 svchost
660 svchost
696 csrss
784 wininit
800 csrss
844 services
860 lsass
868 lsm
896 winlogon
988 #32770 HsMgr ComHookMonitor
1008 svchost
1036 svchost
1068 svchost
1164 SearchProtocolHost
1236 svchost
1332 TCPSVCS
1360 svchost
1480 svchost
1568 spoolsv
1584 GDI+ Hook Window Class LWEMon Logitech Wingman Event Monitor
1608 svchost
1636 svchost
1648 UxdService NvXDSync UxdService
1668 NVSVC64.DLL nvvsvc NvSvc
1760 avgfws
1856 avgwdsvc
1892 k9filter
1900 svchost
1924 CTDevSrv
1936 AVGIDSAgent
1992 NBService
2132 jusched
2404 avgam
2420 avgnsa
2484 GDI+ Hook Window Class AsusAudioCenter Xonar DS Audio Center
2660 WUDFHost
2828 HWSW_SQMSessionWindow itype keyboard
3024 #32770 HsMgr64 ComHookMonitor
3032 WorkerW ImpulseNow GDI+ Window
3064 .NET-BroadcastEventWindow.2.0. IAStorIcon GDI+ Window
3084 audiodg
3128 ShrAliasWindowClass ShrAlias ShrAliasWindow
3204 conhost
3464 caller64
3468 Afx:00400000:0 razerhid razerAbyssushid
3472 IconoidHidden iconoid64 Iconoid Hidden Window
3608 CicLoaderWndClass taskhost Task Host Window
3708 Dwm dwm DWM Notification Window
3716 Samsung PanelMgr SSMMgr Samsung PanelMgr
3748 Progman explorer Program Manager
3776 dpupdchk
3888 AvgWndClass_Tray avgtray AvgTrayMainWnd
3996 avgcsrva
4016 GDI+ Hook Window Class sidebar AVG
4020 Usb30Monitor nusb3mon USB 3.0 Monitor
4336 Afx:400000:0 razertra RazerAbyssusTrayIcon
4348 nvtray
4496 SearchIndexer
4652 daemonu
4664 #32770 RealTemp 38øC 36øC 36øC 42øC
4696 AVGIDSMonitor
4728 IAStorDataMgrSvc
4772 Razer On-the-Fly Sensitivity A razerofa Razer On-the-Fly Sensitivity Adjustment
4784 __ipw_socket_wnd__ tcmd TC 12.11 - TCC Prompt
4920 tooltips_class32 procexp64 Process Explorer - Sysinternals: www.sysinternals.com [Nemesis\NemesisAdmin]
4968 wmpnetwk
5132 KeditFrame32 KEDITW32 KEDIT - [D:\programs\BAT\skyrim_go.btm]
5156 __ipw_socket_wnd__ tcc TCC Prompt
5476 avgrsa
5508 avgcsrva
6152 SearchFilterHost
6376 tooltips_class32 winamp Winamp 5.621
6400 USurface_39545583 Steam Screenshot Manager
6404 conhost
6908 SteamService
7488* __ipw_socket_wnd__ tcc Skyrim Go
TESV ended at 20:10:37 on 12/12/11
Ended at 20:10:37 on 12/12/11 for SJP

More often than not the executable that it latches on to is SearchProtocolHost but that is by no means 100% true, and sometimes it changes more than once, viz:

Code:
Started at 20:31:21 on 10/12/11 with 'SJP'
Starting TESV at 20:31:21 on 10/12/11
TESV executable visible after 0 ticks (7200: "c:\program files (x86)\steam\steamapps\common\skyrim\TESV.exe")
0 [System Process]
4 System
156 svchost
384 smss
464 avgchsva
500 nvvsvc
540 #32770 HsMgr ComHookMonitor
588 IconoidHidden iconoid64 Iconoid Hidden Window
596 HWSW_SQMSessionWindow itype keyboard
724 svchost
736 csrss
824 wininit
836 csrss
884 services
892 lsass
900 lsm
928 winlogon
1028 daemonu
1036 svchost
1076 svchost
1108 svchost
1180 audiodg
1288 svchost
1412 svchost
1544 BasicWindow sidebar CPU Meter
1624 spoolsv
1640 UxdService NvXDSync UxdService
1660 NVSVC64.DLL nvvsvc NvSvc
1688 svchost
1820 avgfws
1868 avgcsrva
1872 TCPSVCS
1900 avgwdsvc
1928 k9filter
1960 CTDevSrv
2032 NBService
2064 SearchIndexer
2092 AVGIDSAgent
2156 Progman explorer Program Manager
2160 avgrsa
2452 avgam
2472 avgnsa
2756 GDI+ Hook Window Class LWEMon Logitech Wingman Event Monitor
2796 svchost
2884 WUDFHost
2932 #32770 HsMgr64 ComHookMonitor
3160 __ipw_socket_wnd__ tcc TCC Prompt
3804 Dwm dwm DWM Notification Window
3864 svchost
3948 ShrAliasWindowClass ShrAlias ShrAliasWindow
3956 CicLoaderWndClass taskhost Task Host Window
3968 TASKENGINEWINDOWCLASS taskeng TaskEng - Task Scheduler Engine Process
4012 GDI+ Hook Window Class AsusAudioCenter Xonar DS Audio Center
4048 IAStorDataMgrSvc
4068 avgcsrva
4100 dpupdchk
4316 Afx:400000:0 razertra RazerAbyssusTrayIcon
4344 .NET-BroadcastEventWindow.2.0. IAStorIcon GDI+ Window
4400 Usb30Monitor nusb3mon USB 3.0 Monitor
4432 Afx:00400000:0 razerhid razerAbyssushid
4460 Samsung PanelMgr SSMMgr Samsung PanelMgr
4472 Razer On-the-Fly Sensitivity A razerofa Razer On-the-Fly Sensitivity Adjustment
4484 AvgWndClass_Tray avgtray AvgTrayMainWnd
4524 jusched
4564 wmpnetwk
4620 WorkerW ImpulseNow GDI+ Window
4652 caller64
4684 KeditFrame32 KEDITW32 KEDIT - [C:hosts]
4932 AVGIDSMonitor
5080 nvtray
5336 PROCEXPL procexp64 Process Explorer - Sysinternals: www.sysinternals.com [Nemesis\NemesisAdmin]
5400 GameOverlayUI
5408* __ipw_socket_wnd__ tcc Skyrim Go
5496 #32770 RealTemp 31øC 24øC 25øC 28øC
5672 Afx:0000000140000000:8:0000000 tcmd TC 12.11 - TCC Prompt
5752 conhost
5816 SearchFilterHost
5884 Afx:00C80000:0 vdDaemon razervdDaemon
6052 SearchProtocolHost
7088 SteamService
7196 conhost
7200 DIEmWin TESV Skyrim
7664 USurface_38414284 Steam Screenshot Manager
7848 WmiPrvSE
TESV executable [7200] still running after 720 checks
TESV executable PID has changed from 7200 to 6464 ()
0 [System Process]
4 System
156 svchost
384 smss
464 avgchsva
500 nvvsvc
540 #32770 HsMgr ComHookMonitor
588 IconoidHidden iconoid64 Iconoid Hidden Window
596 HWSW_SQMSessionWindow itype keyboard
724 svchost
736 csrss
824 wininit
836 csrss
884 services
892 lsass
900 lsm
928 winlogon
1028 daemonu
1036 svchost
1076 svchost
1108 svchost
1180 audiodg
1288 svchost
1412 svchost
1544 BasicWindow sidebar CPU Meter
1624 spoolsv
1640 UxdService NvXDSync UxdService
1660 NVSVC64.DLL nvvsvc NvSvc
1688 svchost
1820 avgfws
1868 avgcsrva
1872 TCPSVCS
1900 avgwdsvc
1928 k9filter
1960 CTDevSrv
2032 NBService
2064 SearchIndexer
2092 AVGIDSAgent
2156 Progman explorer Program Manager
2160 avgrsa
2452 avgam
2472 avgnsa
2560 SearchFilterHost
2756 GDI+ Hook Window Class LWEMon Logitech Wingman Event Monitor
2796 svchost
2884 WUDFHost
2932 #32770 HsMgr64 ComHookMonitor
3160 __ipw_socket_wnd__ tcc TCC Prompt
3804 Dwm dwm DWM Notification Window
3864 svchost
3948 ShrAliasWindowClass ShrAlias ShrAliasWindow
3956 CicLoaderWndClass taskhost Task Host Window
3968 TASKENGINEWINDOWCLASS taskeng TaskEng - Task Scheduler Engine Process
4012 GDI+ Hook Window Class AsusAudioCenter Xonar DS Audio Center
4048 IAStorDataMgrSvc
4068 avgcsrva
4100 dpupdchk
4316 Afx:400000:0 razertra RazerAbyssusTrayIcon
4344 .NET-BroadcastEventWindow.2.0. IAStorIcon GDI+ Window
4400 Usb30Monitor nusb3mon USB 3.0 Monitor
4432 Afx:00400000:0 razerhid razerAbyssushid
4460 Samsung PanelMgr SSMMgr Samsung PanelMgr
4472 Razer On-the-Fly Sensitivity A razerofa Razer On-the-Fly Sensitivity Adjustment
4484 AvgWndClass_Tray avgtray AvgTrayMainWnd
4524 jusched
4564 wmpnetwk
4620 WorkerW ImpulseNow GDI+ Window
4652 caller64
4684 KeditFrame32 KEDITW32 KEDIT - [C:hosts]
4932 AVGIDSMonitor
5080 nvtray
5336 PROCEXPL procexp64 Process Explorer - Sysinternals: www.sysinternals.com [Nemesis\NemesisAdmin]
5408* __ipw_socket_wnd__ tcc Skyrim Go
5496 #32770 RealTemp 34øC 34øC 34øC 34øC
5672 Afx:0000000140000000:8:0000000 tcmd TC 12.11 - TCC Prompt
5752 conhost
5884 Afx:00C80000:0 vdDaemon razervdDaemon
6464 SearchProtocolHost
7088 SteamService
7196 conhost
7664 USurface_38414284 Steam Steam - Update News
TESV executable PID has changed from 6464 to 2560 ()
0 [System Process]
4 System
156 svchost
384 smss
464 avgchsva
500 nvvsvc
540 #32770 HsMgr ComHookMonitor
588 IconoidHidden iconoid64 Iconoid Hidden Window
596 HWSW_SQMSessionWindow itype keyboard
724 svchost
736 csrss
824 wininit
836 csrss
884 services
892 lsass
900 lsm
928 winlogon
1028 daemonu
1036 svchost
1076 svchost
1108 svchost
1180 audiodg
1288 svchost
1412 svchost
1544 BasicWindow sidebar CPU Meter
1624 spoolsv
1640 UxdService NvXDSync UxdService
1660 NVSVC64.DLL nvvsvc NvSvc
1688 svchost
1820 avgfws
1868 avgcsrva
1872 TCPSVCS
1900 avgwdsvc
1928 k9filter
1960 CTDevSrv
2032 NBService
2064 SearchIndexer
2092 AVGIDSAgent
2156 Progman explorer Program Manager
2160 avgrsa
2452 avgam
2472 avgnsa
2560 SearchFilterHost
2756 GDI+ Hook Window Class LWEMon Logitech Wingman Event Monitor
2796 svchost
2884 WUDFHost
2932 #32770 HsMgr64 ComHookMonitor
3160 __ipw_socket_wnd__ tcc TCC Prompt
3804 Dwm dwm DWM Notification Window
3864 svchost
3948 ShrAliasWindowClass ShrAlias ShrAliasWindow
3956 CicLoaderWndClass taskhost Task Host Window
3968 TASKENGINEWINDOWCLASS taskeng TaskEng - Task Scheduler Engine Process
4012 GDI+ Hook Window Class AsusAudioCenter Xonar DS Audio Center
4048 IAStorDataMgrSvc
4068 avgcsrva
4100 dpupdchk
4316 Afx:400000:0 razertra RazerAbyssusTrayIcon
4344 .NET-BroadcastEventWindow.2.0. IAStorIcon GDI+ Window
4400 Usb30Monitor nusb3mon USB 3.0 Monitor
4432 Afx:00400000:0 razerhid razerAbyssushid
4460 Samsung PanelMgr SSMMgr Samsung PanelMgr
4472 Razer On-the-Fly Sensitivity A razerofa Razer On-the-Fly Sensitivity Adjustment
4484 AvgWndClass_Tray avgtray AvgTrayMainWnd
4524 jusched
4564 wmpnetwk
4620 WorkerW ImpulseNow GDI+ Window
4652 caller64
4932 AVGIDSMonitor
5080 nvtray
5336 PROCEXPL procexp64 Process Explorer - Sysinternals: www.sysinternals.com [Nemesis\NemesisAdmin]
5408* __ipw_socket_wnd__ tcc Skyrim Go
5496 #32770 RealTemp 32øC 32øC 32øC 33øC
5672 Afx:0000000140000000:8:0000000 tcmd TC 12.11 - TCC Prompt
5752 conhost
5884 Afx:00C80000:0 vdDaemon razervdDaemon
6464 SearchProtocolHost
7088 SteamService
7196 conhost
7664 USurface_38414284 Steam Screenshot Manager
TESV ended at 21:55:43 on 10/12/11
Ended at 21:55:43 on 10/12/11 for SJP

As I say, I'm stumped, so if anyone has any ideas (and yes, I've just noticed that I'm a handful of builds behind the latest for v12, am in the throes of updating as I type this, and will report back if it makes any difference) then I'd be most grateful.


TCC 12.11.73 x64 Windows 7 [Version 6.1.7601]
Copyright 2011 Rex Conn & JP Software Inc. All Rights Reserved
 
There's some problems with your approach:

1) TCC / @PID is taking a snapshot of the current process list, and then parsing the list looking for a matching name. There's no guarantee that by the time TCC finds a matching name and returns the PID that the process is still active, just that it was active when the snapshot was taken.

2) Windows is somewhat unpredictable about how long it keeps an expired app in the process list, and when it will reuse the PID.

3) If you have an app that starts another app, you won't be able to get the PID with @PID.

4) Windows 7 will require debug privileges to get this info.

5) Unless you have multiple instances of TESV.EXE running (or TESV periodically restarts itself?) I know of no way that the PID could spontaneously change itself. (It would be a Very Bad Thing if Windows is doing it.)

I'd recommend either using PROCESSMONITOR or the ISAPP conditional test in IF / IFF / DO, both of which enumerate the process list rather than getting a snapshot.
 
There's no guarantee that by the time TCC finds a matching name and returns the PID that the process is still active, just that it was active when the snapshot was taken
I don't believe that that is going to matter in this instance. Skyrim is rarely a short-lived executable :)

Windows is somewhat unpredictable about how long it keeps an expired app in the process list, and when it will reuse the PID
The whole point of adding the TASKLIST commands to the code was to get a view of what TCC was being told the active tasks were. There is only ever one instance of TESV.EXE running but once it terminates @PID is somehow finding that name associated with a different process. Since you say that TCC is parsing the process list looking for the given string could it be that Windows is returning duff information that hasn't been cleared out properly (in which case I guess that blows this out of the water)??

Windows 7 will require debug privileges to get this info
What are the implications of that?? If the batch needs to run elevated then that would be a problem since only one of the four users of it know the admin user password. If I grant that privilege to all users of the machine through local policy then what else are they going to be able to do that might present problems somewhere down the line??

Unless you have multiple instances of TESV.EXE running (or TESV periodically restarts itself?) I know of no way that the PID could spontaneously change itself. (It would be a Very Bad Thing if Windows is doing it.)
There is only one instance, and it isn't restarting itself - if someone plays the game for a couple of hours (without a crash) then I see the hourly log entry as per the code above. The issue described only happens when the user exits the game (I've not noticed it happen after a CTD but there have only been a handful of those) so it isn't anything that the game executable is perpetrating.

I'd recommend either using PROCESSMONITOR or the ISAPP conditional test in IF / IFF / DO, both of which enumerate the process list rather than getting a snapshot.
Okay. I took a look at PROCESSMONITOR when I discovered it whilst trying to debug the @PID issue and decided that it was non-trivial to change the whole batch to use it instead. ISAPP might provide a way of doing this, but the help mentions the need for debug privileges which plays back to the question above.
 
Back
Top