Jump to content

Pid help


Recommended Posts

The OP doesn't seem to really be interested in the child PID, only that he waits until it is closed. In that case, I stick by my original code. Run the parent 'launcher' with Run() so the PID is returned, wait for it to close with ProcessWaitClose(), when that returns he can be as reasonably sure as possible the child process has been created. Then run my code. One of two things happens -

1) the child process is found, and he waits for it to close

2) the child process is not found, $child = -1, which means it has already ended and it's safe to proceed

Edited by wraithdu
Link to comment
Share on other sites

Hm. I'm a little bit surprised that a non-existent parent PID is returned for the child. I did not expect that because it's dangerous. I guess there is nothing wrong with wraithdu's code after-all.

Link to comment
Share on other sites

Thank you all for all your assistance. Very impressed with the help you have gave.

I am a little confused with the replies as the replies seem to run a process from the script then run a different process after that. I am not sure I have explained myself fully or I am misunderstanding the examples.

Here is whay I am up against in a bit more detail ..

My script executes a process called JobLauncher.exe and gives it a paramater to use. This process launches no problems and I can obtain its pid with no issues. The problem I get is this process then launches its own process called job.exe and closes down the initial Joblauncher.exe.

The job.exe stays open for some time until its work is complete. I need to know what pid JobLauncher spawns.

To make things more complicated there may already be many Job.exe processes active. This is why I cannot simply get a pid of the process name as I do not know which one is which.

My script may be launching more than 1 of these processes and it will be looking on a regular interval for when the PID dies off so I know when one of them completes. Each job.exe will have the task of executing different tasks hence the need to know when I launch the main program (joblauncher) I need to know exactly which resultant PID it spawns.

I am sure you have answered my question in the post but I am unable to get it working as it seems the examples you have posted launch both the seperate processes from the script whereas mine does not - It launches 1 executable and that exe then launches its own sub process and then closes down

Hope you can help further - and again many thanks for all your time and effort so far.

Link to comment
Share on other sites

The _ProcessListProperties() UDF in Example Scripts includes the PPID field for each process. There is still a bit of a race condition possible, but for anything other than extremely short-lived children, it should work fine.

If you want to get down and geeky, I think you can get a WMI event for new process creations and check the parent IDs from that.

:D

Seems the _ProcessListProperties() can tell me the parent pid of the process that launches. This would have been exactly what I want, the only problem is I seem to have been shot down as the parent is a service that appears to be running that creates the child process - I did not expect that - This means my initial process never spawns another process it merely passes some information to a resident service that then launches the child process..

I think that puts the nail in it unfortunatly - there is no way for me to tell as this is a service constantly running as a middle man ..

Thanks for all your help once again

Link to comment
Share on other sites

Seems the _ProcessListProperties() can tell me the parent pid of the process that launches. This would have been exactly what I want, the only problem is I seem to have been shot down as the parent is a service that appears to be running that creates the child process - I did not expect that - This means my initial process never spawns another process it merely passes some information to a resident service that then launches the child process..

I think that puts the nail in it unfortunatly - there is no way for me to tell as this is a service constantly running as a middle man ..

Thanks for all your help once again.

That scenario leaves you some wiggle room. If the multiple Job.exe instances usually last a while (greater than a couple hundred milliseconds), then you could ProcessList() them, run your task, then ProcessList() them again to find the new one by comparison of the arrays.

Also, the array returned from _ProcessListProperties() includes the calling command line, which may have relevant parameters that would ID the particular instance you want. List all the Job.exe processes with _ProcessListProperties() and check element [n][9] to see if they have useful identifying info there, i.e.: "C:\Program Files\MyProg\Job.exe /param1 /param2 /SomethingUnique"

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

That scenario leaves you some wiggle room. If the multiple Job.exe instances usually last a while (greater than a couple hundred milliseconds), then you could ProcessList() them, run your task, then ProcessList() them again to find the new one by comparison of the arrays.

Also, the array returned from _ProcessListProperties() includes the calling command line, which may have relevant parameters that would ID the particular instance you want. List all the Job.exe processes with _ProcessListProperties() and check element [n][9] to see if they have useful identifying info there, i.e.: "C:\Program Files\MyProg\Job.exe /param1 /param2 /SomethingUnique"

:D

@Valik - I unfortunatly dont control the source code. I am manipulating the features of a product on one of my servers.

@PsaltyDS - Excellent news - I rechecked the output on _ProcessListProperties() and this actually does reveal the command line used to execute the job.exe process. I have emulated the command line and it does do what I am looking for without launching all the parent processes. Brilliant news - Cannot beleive I missed this column.

Excellent work ....

Link to comment
Share on other sites

@Valik - I unfortunatly dont control the source code. I am manipulating the features of a product on one of my servers.

@PsaltyDS - Excellent news - I rechecked the output on _ProcessListProperties() and this actually does reveal the command line used to execute the job.exe process. I have emulated the command line and it does do what I am looking for without launching all the parent processes. Brilliant news - Cannot beleive I missed this column.

Excellent work ....

Glad it helped.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...