• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ GetProcessId函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: restoreBackandParams

Bool restoreBackandParams(
    void*            self,
    BackendParams    param)
{
    strcpy(DataDir, param->dataDir, MAX_PATH);

    memcpy(ListenSockets, &param->listenSockets, sizeof(socket_type));

    CancelKey   = param->cancelKey;
    ChildSlot   = param->childSlot;

    ProcId      = GetProcessId(GetCurrentProcess());

    StartTime   = param->startTime;
    ReloadTime  = param->reloadTime;

    LoggerFileTime     = param->loggerFileTime;
    RedirectDone       = param->redirectDone;
    maxFileDescriptors = param->maxSafeFileDescriptors;

    memcpy(&logPipe, &param->logPipe, sizeof(logPipe));

    strcpy(ExecPath, param->execPath);

    return True;
}
开发者ID:riryk,项目名称:RussoDB,代码行数:26,代码来源:processhelper.c


示例17: JpfsvGetProcessIdContext

DWORD JpfsvGetProcessIdContext(
	__in JPFSV_HANDLE ContextHandle
	)
{
	PJPFSV_CONTEXT Context = ( PJPFSV_CONTEXT ) ContextHandle;

	ASSERT( Context && Context->Signature == JPFSV_CONTEXT_SIGNATURE );
	if ( Context && Context->Signature == JPFSV_CONTEXT_SIGNATURE )
	{
		if ( Context->ProcessHandle == JPFSV_KERNEL_PSEUDO_HANDLE )
		{
			//
			// Kernel context.
			//
			return JPFSV_KERNEL;
		}
		else
		{
			return GetProcessId( Context->ProcessHandle );
		}
	}
	else
	{
		return 0;
	}
}
开发者ID:jpassing,项目名称:ntrace,代码行数:26,代码来源:context.c


示例18: TerminateIfRunning

bool TerminateIfRunning ( void )
{
    bool bAlreadyRunning = false;
    unsigned int index = 0;

    DWORD dwOwnPID   = GetProcessId ( GetCurrentProcess () );
    HANDLE hSnapShot = CreateToolhelp32Snapshot ( TH32CS_SNAPPROCESS, 0 );

    PROCESSENTRY32* processInfo = new PROCESSENTRY32;
    processInfo->dwSize = sizeof ( PROCESSENTRY32 );

    while ( Process32Next ( hSnapShot, processInfo ) != 0 )
    {
        // Convert WCHAR to const char *
        const char * strFileName = reinterpret_cast < const char * >( processInfo->szExeFile );

        if ( !strcmp ( strFileName, "_TODO_EXE_NAME_.exe" ) )
        {
            if ( processInfo->th32ProcessID != dwOwnPID )
            {
                bAlreadyRunning = true;
                break;
            }
        }
    }

    CloseHandle ( hSnapShot );
    delete processInfo;

    return bAlreadyRunning;
}
开发者ID:Dellware78,项目名称:mtasa-scripteditor,代码行数:31,代码来源:main.cpp


示例19: log_init_thread

void log_init_thread()
{
	if (!logger_attached)
		return;
	LPCWSTR pipeName = L"\\\\.\\pipe\\flog_server";
	for (;;)
	{
		hLoggerPipe = CreateFileW(pipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
		if (hLoggerPipe == INVALID_HANDLE_VALUE)
		{
			/* Non critical error code, just wait and try connecting again */
			if (GetLastError() != ERROR_PIPE_BUSY || !WaitNamedPipeW(pipeName, NMPWAIT_WAIT_FOREVER))
			{
				logger_attached = 0;
				break;
			}
			continue;
		}
		/* Send initial request */
		struct request request;
		request.magic = PROTOCOL_MAGIC;
		request.version = PROTOCOL_VERSION;
		request.pid = GetProcessId(GetCurrentProcess());
		request.tid = GetThreadId(GetCurrentThread());
		DWORD written;
		if (!WriteFile(hLoggerPipe, &request, sizeof(request), &written, NULL))
		{
			CloseHandle(hLoggerPipe);
			logger_attached = 0;
		}
		break;
	}
}
开发者ID:mt206,项目名称:flinux,代码行数:33,代码来源:log.c


示例20: KillProcessByNameExcludingMyself

void KillProcessByNameExcludingMyself(LPCTSTR lpName)
{
    HANDLE hCurrentProcess;
    DWORD dwCurrentProcess;
    HANDLE hSnapShot;
    PROCESSENTRY32 pEntry;
    BOOL hRes;
    HANDLE hProcess;

    hCurrentProcess = GetCurrentProcess();
    dwCurrentProcess = GetProcessId(hCurrentProcess);

    hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
    pEntry.dwSize = sizeof(pEntry);
    hRes = Process32First(hSnapShot, &pEntry);
    while (hRes)
    {
        if (strcmp(pEntry.szExeFile, lpName) == 0 && pEntry.th32ProcessID != dwCurrentProcess)
        {
            hProcess = OpenProcess(PROCESS_TERMINATE, 0,
                (DWORD) pEntry.th32ProcessID);
            if (hProcess != NULL)
            {
                TerminateProcess(hProcess, 9);
                CloseHandle(hProcess);
            }
        }
        hRes = Process32Next(hSnapShot, &pEntry);
    }
    CloseHandle(hSnapShot);
}
开发者ID:sh123,项目名称:papi_proxy,代码行数:31,代码来源:papi_proxy.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ GetProcessTimes函数代码示例发布时间:2022-05-30
下一篇:
C++ GetProcessAffinityMask函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap