当前位置: 首页>>代码示例>>C++>>正文


C++ GetProcessId函数代码示例

本文整理汇总了C++中GetProcessId函数的典型用法代码示例。如果您正苦于以下问题:C++ GetProcessId函数的具体用法?C++ GetProcessId怎么用?C++ GetProcessId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetProcessId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AppDrone

VOID
AppDrone() {
    ULONG i, j;
    HANDLE outp;
    CHAR outstring[80];

    outp = CreateFile('s');

    RtlFormatString(outstring, 80, "\r\nDrone with PID:%d started\r\n", GetProcessId());
    WriteString(outp, outstring);
    KdPrint("in drone 1");
    //Sleep(DRONE_SLEEP_TIME);
    KdPrint("in drone after sleep");
    RtlFormatString(outstring, 80, "\r\nDrone with PID:%d still alive\r\n", GetProcessId());

    for (i = 0; i < 3; i++) {
        KdPrint("in drone 2");
        WriteString(outp, outstring);
        for(j=0;j<0xFFFFFF;j++);
        //Sleep(DRONE_SLEEP_TIME);
    }
    RtlFormatString(outstring, 80, "\r\nDrone with PID:%d killing my self\r\n", GetProcessId());
    KdPrint("in drone 3");
    WriteString(outp, outstring);
    CloseHandle(outp);
    KillMe();
}
开发者ID:wjcsharp,项目名称:arcos-os,代码行数:27,代码来源:drone.c

示例2: CaptureAndSuspendProcess

DWORD CALLBACK CaptureAndSuspendProcess(LPVOID)
{
  ImpersonateAnonymousToken(GetCurrentThread());

  while (NtGetNextProcess(nullptr, MAXIMUM_ALLOWED, 0, 0, &g_hProcess) != 0)
  {
  }
  NTSTATUS status = NtSuspendProcess(g_hProcess);

  printf("Suspended process: %08X %p %d\n", status, g_hProcess, GetProcessId(g_hProcess));
  RevertToSelf();

  SetProcessId(GetProcessId(g_hProcess));
  
  WCHAR cmdline[] = L"notepad.exe";
  STARTUPINFO startInfo = {};
  PROCESS_INFORMATION procInfo = {};
  startInfo.cb = sizeof(startInfo);
  if (CreateProcessWithLogonW(L"user", L"domain", L"password", LOGON_NETCREDENTIALS_ONLY,
    nullptr, cmdline, CREATE_SUSPENDED, nullptr, nullptr, &startInfo, &procInfo))
  {
    printf("Created process %d\n", procInfo.dwProcessId);
  }
  else
  {
    printf("Create error: %d\n", GetLastError());
  }
  TerminateProcess(g_hProcess, 0);
  ExitProcess(0);

  return 0;
}
开发者ID:0x24bin,项目名称:exploit-database,代码行数:32,代码来源:39740.cpp

示例3: waitpid

void FProcState::Wait()
{
	if (bHasBeenWaitedFor)
	{
		return;	// we could try waitpid() another time, but why
	}

	for(;;)	// infinite loop in case we get EINTR and have to repeat
	{
		siginfo_t SignalInfo;
		if (waitid(P_PID, GetProcessId(), &SignalInfo, WEXITED))
		{
			if (errno != EINTR)
			{
				int ErrNo = errno;
				UE_LOG(LogHAL, Fatal, TEXT("FLinuxPlatformProcess::WaitForProc: waitid for pid %d failed (errno=%d, %s)"), 
					static_cast< int32 >(GetProcessId()), ErrNo, ANSI_TO_TCHAR(strerror(ErrNo)));
				break;	// exit the loop if for some reason Fatal log (above) returns
			}
		}
		else
		{
			check(SignalInfo.si_pid == GetProcessId());

			ReturnCode = (SignalInfo.si_code == CLD_EXITED) ? SignalInfo.si_status : -1;
			bHasBeenWaitedFor = true;
			bIsRunning = false;	// set in advance
			break;
		}
	}
}
开发者ID:johndpope,项目名称:UE4,代码行数:31,代码来源:LinuxPlatformProcess.cpp

示例4: MyCreateProcessCommon

static void
MyCreateProcessCommon(BOOL bRet,
                      DWORD dwCreationFlags,
                      LPPROCESS_INFORMATION lpProcessInformation)
{
    if (!bRet) {
        debugPrintf("inject: warning: failed to create child process\n");
        return;
    }

    DWORD dwLastError = GetLastError();

    if (isDifferentArch(lpProcessInformation->hProcess)) {
        debugPrintf("inject: error: child process %lu has different architecture\n",
                    GetProcessId(lpProcessInformation->hProcess));
    } else {
        char szDllPath[MAX_PATH];
        GetModuleFileNameA(g_hThisModule, szDllPath, sizeof szDllPath);

        if (!injectDll(lpProcessInformation->hProcess, szDllPath)) {
            debugPrintf("inject: warning: failed to inject into child process %lu\n",
                        GetProcessId(lpProcessInformation->hProcess));
        }
    }

    if (!(dwCreationFlags & CREATE_SUSPENDED)) {
        ResumeThread(lpProcessInformation->hThread);
    }

    SetLastError(dwLastError);
}
开发者ID:swq0553,项目名称:apitrace,代码行数:31,代码来源:injectee.cpp

示例5: PsProcessHandleToId

DWORD
PsProcessHandleToId(HANDLE ProcessHandle)
{
    HANDLE targetHandle;
    DWORD processId;

    if (ProcessHandle == GetCurrentProcess())
    {
        return GetCurrentProcessId();
    }

    processId = GetProcessId(ProcessHandle);

    if (processId)
    {
        return processId;
    }

    if (!PsCopyHandle(GetCurrentProcess(),
                      ProcessHandle,
                      &targetHandle,
                      PROCESS_QUERY_INFORMATION,
                      FALSE))
    {
        return 0;
    }

    processId = GetProcessId(targetHandle);

    CloseHandle(targetHandle);

    return processId;
}
开发者ID:DarkoreXOR,项目名称:hooklib,代码行数:33,代码来源:process_utils.cpp

示例6: main

int main(int argc, char* argv[]) 
{
	int a = fork();
	char *env[] = {"PATH=C:\\TEST", NULL};

	if(a > 0)
	{
		printf("\nParent ProcessID : %d\n",GetProcessId());

		waitpid(a);

		printf("\nAfter Child Process has exited");
			
		sleep(10);
			
		printf("\nParent : After Sleep");
		

	}
	else
	{
		printf("\nChild ProcessID : %d\n",GetProcessId());
		char *inp[] = {"bin/hello","a","b"};

		execvpe(inp[0],inp,env);
	}

	return 0;

}
开发者ID:sumanthkanuparthi,项目名称:Operating-System,代码行数:30,代码来源:fork.c

示例7: check

bool FProcState::IsRunning()
{
	if (bIsRunning)
	{
		check(!bHasBeenWaitedFor);	// check for the sake of internal consistency

		// check if actually running
		int KillResult = kill(GetProcessId(), 0);	// no actual signal is sent
		check(KillResult != -1 || errno != EINVAL);

		bIsRunning = (KillResult == 0 || (KillResult == -1 && errno == EPERM));

		// additional check if it's a zombie
		if (bIsRunning)
		{
			for(;;)	// infinite loop in case we get EINTR and have to repeat
			{
				siginfo_t SignalInfo;
				SignalInfo.si_pid = 0;	// if remains 0, treat as child was not waitable (i.e. was running)
				if (waitid(P_PID, GetProcessId(), &SignalInfo, WEXITED | WNOHANG | WNOWAIT))
				{
					if (errno != EINTR)
					{
						int ErrNo = errno;
						UE_LOG(LogHAL, Fatal, TEXT("FLinuxPlatformProcess::WaitForProc: waitid for pid %d failed (errno=%d, %s)"), 
							static_cast< int32 >(GetProcessId()), ErrNo, ANSI_TO_TCHAR(strerror(ErrNo)));
						break;	// exit the loop if for some reason Fatal log (above) returns
					}
				}
				else
				{
					bIsRunning = ( SignalInfo.si_pid != GetProcessId() );
					break;
				}
			}
		}

		// If child is a zombie, wait() immediately to free up kernel resources. Higher level code
		// (e.g. shader compiling manager) can hold on to handle of no longer running process for longer,
		// which is a dubious, but valid behavior. We don't want to keep zombie around though.
		if (!bIsRunning)
		{
			UE_LOG(LogHAL, Log, TEXT("Child %d is no more running (zombie), Wait()ing immediately."), GetProcessId() );
			Wait();
		}
	}

	return bIsRunning;
}
开发者ID:johndpope,项目名称:UE4,代码行数:49,代码来源:LinuxPlatformProcess.cpp

示例8: Log

void Log(char* szFormat, ...)
{
	va_list vaArgs;

	va_start(vaArgs, szFormat);
	int len = _vscprintf(szFormat, vaArgs);
	char* szString = new char[len+1];
	vsprintf_s(szString, len+1, szFormat, vaArgs);
	va_end(vaArgs);

	time_t tTime;
	time(&tTime);
	char szTime[128] = "";
	struct tm time;
	localtime_s(&time, &tTime);
	strftime(szTime, sizeof(szTime), "%x %X", &time);

	char path[_MAX_PATH+_MAX_FNAME] = "";
	sprintf_s(path, sizeof(path), "%sd2bs.log", Vars.szPath);

#ifdef DEBUG
	FILE* log = stderr;
#else
	FILE* log = _fsopen(path, "a+", _SH_DENYNO);
#endif
	fprintf(log, "[%s] D2BS %d: %s\n", szTime, GetProcessId(GetCurrentProcess()), szString);
#ifndef DEBUG
	fflush(log);
	fclose(log);
#endif
	delete[] szString;
}
开发者ID:ds-hwang,项目名称:d2bs,代码行数:32,代码来源:D2Helpers.cpp

示例9: C_GetProcMemInfo

BOOL MEMINFO_API C_GetProcMemInfo(_In_  DWORD  dwProcId, _Out_  PPROCMEMINFO_C pProcMemInfo){
	HANDLE hProc = NULL;
	MEMORYSTATUSEX status;
	PROCESS_MEMORY_COUNTERS procMemCtr;

	printf("\n\n~~~~ INFORMACAO LOCAL DO PROCESSO ~~~~~");

	status.dwLength = sizeof (status);

	if (hProc = OpenProcess(PROCESS_VM_READ|PROCESS_QUERY_INFORMATION, FALSE, dwProcId) == NULL || !GlobalMemoryStatusEx(&status) ||
		!GetProcessMemoryInfo(hProc, &procMemCtr, sizeof(PROCESS_MEMORY_COUNTERS))){
		printf("ERROR: %s\n", GetLastError());
		return FALSE;
	}

	printf("\nProcess ID = %u", GetProcessId(hProc));
	printf("\nTotal de espaco de enderecamento virtual existente: %llu KiB = %llu MiB", status.ullTotalVirtual / KiloB, status.ullTotalVirtual / MegaB);
	printf("\nTotal de espaco de enderecamento virtual disponivel: %llu KiB = %llu MiB", status.ullAvailVirtual / KiloB, status.ullAvailVirtual / MegaB);
	printf("\nDimensao do Working Set: %u KiB = %.2f MiB", procMemCtr.WorkingSetSize / KiloB, (double)procMemCtr.WorkingSetSize / MegaB);

	// Afectar a struct _out_
	pProcMemInfo->processId = dwProcId;
	pProcMemInfo->workingSetSize = procMemCtr.WorkingSetSize;
	pProcMemInfo->totalVirtualSpace = status.ullTotalVirtual;
	pProcMemInfo->availableVirtualSpace = status.ullAvailVirtual;

	printf("\n\nClique em qualquer tecla para terminar..."); getchar();
	CloseHandle(hProc);
	return TRUE;
}
开发者ID:pdsrebelo,项目名称:SO_1314V_Series,代码行数:30,代码来源:Exercicio5.c

示例10: GetProcessId

int KProcess::getProcessId() {
#ifdef _WIN32
	return GetProcessId(pid);
#else
	return pid;
#endif
}
开发者ID:wirror800,项目名称:kangle,代码行数:7,代码来源:KProcess.cpp

示例11: fork

int
fork(void)
{
	RTL_USER_PROCESS_INFORMATION info;
	NTSTATUS result;

	if (w32_fork == NULL)
		return -ENOSYS;
	/* lets do this */
	result = w32_fork(RTL_CLONE_FLAGS, NULL, NULL, NULL, &info);
	if (result == CLONE_PARENT) {
		pid_t pid = GetProcessId(info.Process);
		ResumeThread(info.Thread);
		CloseHandle(info.Process);
		CloseHandle(info.Thread);
		return pid;
	} else if (result == CLONE_CHILD) {
		/* fix stdio */
		AllocConsole();
		return 0;
	} else
		return -1;

	return -1;
}
开发者ID:n13l,项目名称:kbuild,代码行数:25,代码来源:fork.c

示例12: qDebug

void CdbDumperHelper::moduleLoadHook(const QString &module, HANDLE debuggeeHandle)
{
    if (loadDebug > 1)
        qDebug() << "moduleLoadHook" << module << m_state << debuggeeHandle;
    switch (m_state) {
    case Disabled:
    case Initialized:
        break;
    case NotLoaded:
        // Try an inject load as soon as a Qt lib is loaded.
        // for the thread to finish as this would lock up.
        if (m_tryInjectLoad && module.contains(QLatin1String("Qt"), Qt::CaseInsensitive)) {
            // Also shows up in the log window.
            m_manager->showStatusMessage(msgLoading(m_library, true), messageTimeOut);
            QString errorMessage;
            SharedLibraryInjector sh(GetProcessId(debuggeeHandle));
            if (sh.remoteInject(m_library, false, &errorMessage)) {
                m_state = InjectLoading;
            } else {
                m_state = InjectLoadFailed;
                // Ok, try call loading...
                m_manager->showDebuggerOutput(LogMisc, msgLoadFailed(m_library, true, errorMessage));
            }
        }
        break;
    case InjectLoading:
        // check if gdbmacros.dll loaded
        if (module.contains(QLatin1String(dumperModuleNameC), Qt::CaseInsensitive)) {
            m_state = Loaded;
            m_manager->showDebuggerOutput(LogMisc, msgLoadSucceeded(m_library, true));
        }
        break;
    }
}
开发者ID:TheProjecter,项目名称:project-qtcreator,代码行数:34,代码来源:cdbdumperhelper.cpp

示例13: evalProcesses

int evalProcesses(HANDLE hProcess)
{
    if (NULL == hProcess)
        return 0;

    unsigned int totalMemUsage = 0;
    DWORD processID = GetProcessId(hProcess);
  
    HANDLE hProcessSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    PROCESSENTRY32 processEntry = { 0 };
    processEntry.dwSize = sizeof(PROCESSENTRY32);

    // Retrieves information about the first process encountered in a system snapshot
    if(Process32First(hProcessSnapshot, &processEntry)) {
        do {
            // if th32processID = processID, we are the parent process!  
            // if th32ParentProcessID = processID, we are a child process!
            if ((processEntry.th32ProcessID == processID) || (processEntry.th32ParentProcessID == processID)) {
                unsigned int procMemUsage = 0;
                // Record parent process memory
                procMemUsage = getMemoryInfo(processEntry.th32ProcessID);
                totalMemUsage += procMemUsage;
            }
          // Retrieves information about the next process recorded in a system snapshot.   
        } while(Process32Next(hProcessSnapshot, &processEntry));
    }

    CloseHandle(hProcessSnapshot);
    return totalMemUsage;
}
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:31,代码来源:main.cpp

示例14: OpenProcess

bool 
Application_ClientConfigManager::closeProcess(DWORD processId, DWORD* error)
{
	HANDLE hProcess = OpenProcess(PROCESS_TERMINATE,TRUE, processId);
	if(hProcess == NULL)
	{
		*error = GetLastError();
		if(*error == ERROR_INVALID_PARAMETER)
		{
			*error = CAPTURE_PE_PROCESS_ALREADY_TERMINATED;
		}
	} else {
		EnumWindows(Application_ClientConfigManager::EnumWindowsProc, (LPARAM)processId);

		DWORD tempProcessId = GetProcessId(hProcess);
		if(tempProcessId == processId)
		{
			if(!TerminateProcess(hProcess, 0))
			{
				*error = GetLastError();
			} else {
				*error = CAPTURE_PE_PROCESS_TERMINATED_FORCEFULLY;
			}
		} else {
			return true;
		}
	}
	return false;
}
开发者ID:ph0sec,项目名称:CaptureBAT-client,代码行数:29,代码来源:Application_ClientConfigManager.cpp

示例15: AppIsAlreadyRunning

BOOL AppIsAlreadyRunning()
{
    BOOL bRunning=FALSE;
    CString strAppName;
    strAppName = "ZuneNowPlaying.exe";
    DWORD dwOwnPID = GetProcessId(GetCurrentProcess());
    HANDLE hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    PROCESSENTRY32* processInfo=new PROCESSENTRY32;
    processInfo->dwSize=sizeof(PROCESSENTRY32);
    int index=0;
    while(Process32Next(hSnapShot,processInfo)!=FALSE)
    {
		CString pName = (LPCWSTR)processInfo->szExeFile;
		if (pName.CompareNoCase(strAppName) == 0)
        {
            if (processInfo->th32ProcessID != dwOwnPID)
            {
                bRunning=TRUE;
                break;
            }
        }
    }
    CloseHandle(hSnapShot);
    delete processInfo;
    return bRunning;
}
开发者ID:lesmo,项目名称:zune-now-playing,代码行数:26,代码来源:ZuneNowPlaying.cpp


注:本文中的GetProcessId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。