- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there a way to get the parent process ID in Visual Fortran ?
Or should I have to mix language ?
Or should I have to mix language ?
Link Copied
12 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sure, you'd do it the same way as in C. What OS?
James
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Um, parent process ID? Windows does not even have concept of parent and child processes -- it's a Unixian thingo. One can spawn a "child" process via CreateProcess, but the relationship between "child" and "parent" is very weak and AFAIK there's no way to reach the "parent" process (unless the "parent" passes that information explicitly, e.g. using command line). What exactly you're trying to do?
Jugoslav
Jugoslav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jugoslav, the relationship may be "weak" but it is still there, and such information accessible.
James
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
James, I'm affraid you'll have to support that statement with a code sample :-).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, attached.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, you win -- I didn't count on undocumented APIs :-).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Actually it is the concept that is important! I illustrated one way to do it, there is another using documented APIs, it just requires more code.
James
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
GetCurrentProcessID in kernel32 returns this.
HTH,
Gerry T.
HTH,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, GetCurrentProcessID returns the current process id as the name says, not that of the parent.
James
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
That's correct. However, if you snapshot the system via CreateToolHelp32Snapshot, then the snapshot and GetCurrentProcessID allow you to get the process entry data for the current app and hence the parent process id. This is then passed with the snapshot to Process32First(Next) to reveal the name of the parent process as the last member of the PROCESSENTRY32 struct. This approach is preferable to use of internal functions of ntdll as advised in MSDN. Also, snapshots can reveal details on app modules (including loaded ocx's, dll's, and their versioning info) and the threads spawned by the app, wittingly or otherwise.
Ciao,
Gerry T.
Ciao,
Gerry T.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Gerry, yes, that approach is fine in practice although it would be quite a bit more verbose than my example, which was intended to demonstrate a concept. Note that I also mentioned there were more official interfaces available, but didn't have time to whip up an example based on that approach just to show that it was possible.
Cheers,
James
Cheers,
James
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi James
I found your demo to be highly instructive and I'm sorry if I came across as unappreciative. Snapshotting is more bother and besides it hasn't made into CVF's kernel32 yet.
Have you noticed that if you run it from the ide, the parent is the ide; if you double click the .exe, the parent is Explorer; and if you shell it, the parent is the sheller. Ditto for the snapshot approach. I hope my pc hasn't been invaded by Raelians, :-).
Ciao,
Gerry T.
I found your demo to be highly instructive and I'm sorry if I came across as unappreciative. Snapshotting is more bother and besides it hasn't made into CVF's kernel32 yet.
Have you noticed that if you run it from the ide, the parent is the ide; if you double click the .exe, the parent is Explorer; and if you shell it, the parent is the sheller. Ditto for the snapshot approach. I hope my pc hasn't been invaded by Raelians, :-).
Ciao,
Gerry T.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page