Last active
February 22, 2016 13:33
-
-
Save OsandaMalith/a4463b15da8a0e105c83 to your computer and use it in GitHub Desktop.
This will find the PPID - Parent Process ID of the give PID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <stdio.h> | |
| #include "tlhelp32.h" | |
| /* Title: This will find the PPID - Parent Process ID of the give PID | |
| * Author: Osanda Malith Jayathissa (@OsandaMalith) | |
| * Example: ppid.exe 1620 | |
| * PID: 1620 | PPID: 776 | Name: calc.exe | |
| */ | |
| int main(int argc, char *argv[]) { | |
| int pid = 0; | |
| HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | |
| PROCESSENTRY32 pe; | |
| pe.dwSize = sizeof(PROCESSENTRY32); | |
| pid = (argc > 1) ? atoi(argv[1]) : GetCurrentProcessId(); | |
| if(Process32First(h, &pe)) { | |
| do | |
| if (pe.th32ProcessID == pid) | |
| printf("PID: %i | PPID: %i | Name: %s\n", pid, pe.th32ParentProcessID, pe.szExeFile); | |
| while(Process32Next(h, &pe)); | |
| } | |
| CloseHandle(h); | |
| } | |
| //EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment