Subscribe Bookmark RSS Feed

How to use JSL to count the active running processes in windows,e.g. number of notepad.exe?

zyhuang75

Community Trekker

Joined:

Aug 24, 2015

I have a problem to count active processes in windows memory.

I am not familar with windows API. Could anyone help on this using DLL function to count the number of running process for a given process name?

If you open 3 notepad.exe, then window task manager has three notepad session running.

I need a JSL function that takes the process name as input, and number of process as return.

Thank you very much!

4 REPLIES
Craige_Hales

Staff

Joined:

Mar 21, 2013

Started here How do you list all processes on the command line in Windows? - Super User

and wrote this


x=runprogram(executable("wmic"),options({"process list"}),


  readfunction(function({this},write(this<<read)))


);


you'll probably want to parse the text from this<<read rather than just dumping it to the log via write().  Lots of text you don't want, probably, and stuff like "C:\Program Files (x86)\Microsoft Office\Office15\OUTLOOK.EXE"

Craige
zyhuang75

Community Trekker

Joined:

Aug 24, 2015

Craige,

thanks for your reply.I have two more questions:

1. looks like run program is not a function in JMP9 as I am still using JMP9.

2. Does your solution write a file to harddisk? I am trying to do parallel sessions and using waiting in the endless loop. When the total process count is zero, then break the loop and proceed the rest JSL code. If writing file to hard disk, that's less preferable compared to using DLL to get the info directly from memory.

thanks!

Craige_Hales

Staff

Joined:

Mar 21, 2013

RunProgram first appeared in JMP 11.  It does not use a disk file for communication between JMP and the external program; it uses stdin and stdout.  Depending on what your application needs, you might want to run the notepad.exe program from runProgram rather than using RunProgram to run another program to figure out if notepad.exe has finished.  (You could avoid polling completely.)

With JMP 9 you still have several ways to make this work.  You might want to investigate automation to use another language, like visual basic perhaps, to control JMP and notepad.exe.  You might want to write a .BAT file and use JMP's open() to run the bat file.  This does require a polling loop to determine when the bat file is finished.  You can use JMP's wait( seconds ) function to let JMP sleep between polls.  Finally, as your original question suggests, you could use JMP's DLL interface to access a system DLL. This post suggests the better DLL interface appeared in JMP 10; it might not be possible to make the required DLL calls with the older interface.  I don't know what API/DLL you would need.

Craige
zyhuang75

Community Trekker

Joined:

Aug 24, 2015

Craige,

I tried the runprogram function in JMP 11 then write a count words function. I can get the solution I want. Many thanks!

Another interesting thing why I do this is because I noticed open() a text file function is changed from upgrading JMP 9 to 11.

I use JMP 9 to trigger a .exe file to do mutilple threading database query then after all .exe session is completed, rollup the data.

In JMP9 when I open the data file it always succeed, however, in JMP11 many times it gives a warning incomplete data file read and miss half. The data file size is typically >2M-3M, not too big. Not sure what really has been changed in JMP11. Otherwise, I don't need to bother to find solution like this.

Again thanks for the solution.