Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

How to get process id

#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
#include <tchar.h>

std::uint32_t get_proc_id(const std::wstring& name)
{
	auto result = 0ul;
	auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

	if (snapshot == INVALID_HANDLE_VALUE)
		return result;

	auto pe32w = PROCESSENTRY32W{};				// use the wide version of the struct
	pe32w.dwSize = sizeof(PROCESSENTRY32W);

	if (!Process32FirstW(snapshot, &pe32w))
		return CloseHandle(snapshot), result;

	while (Process32NextW(snapshot, &pe32w))
	{
		if (name == pe32w.szExeFile)			// use std::wstring's operator, not comparing pointers here
		{
			result = pe32w.th32ProcessID;
			break;
		}
	}

	CloseHandle(snapshot);
	return result;
}

int main()
{
	const auto pid = get_proc_id(L"explorer.exe");
	std::cout << pid;

	std::cin.get();
}
Comment

how to get process id in linux

lsof -i tcp:3000
kill -9 pId
Comment

To get process ID

julien@ubuntu:~/c/shell$ cat pid.c
#include <stdio.h>
#include <unistd.h>

/**
 * main - PID
 *
 * Return: Always 0.
 */
int main(void)
{
    pid_t my_pid;

    my_pid = getpid();
    printf("%u
", my_pid);
    return (0);
}
julien@ubuntu:~/c/shell$ gcc -Wall -Werror -pedantic pid.c -o mypid && ./mypid
3237
julien@ubuntu:~/c/shell$ ./mypid 
3238
julien@ubuntu:~/c/shell$ ./mypid 
3239
julien@ubuntu:~/c/shell$
Comment

PREVIOUS NEXT
Code Example
Shell :: git undo changes single file 
Shell :: installing appwrite on docker 
Shell :: py pip install error winerror the system cannot find the .exe.deleteme 
Shell :: Basic Authorization failed for user 
Shell :: flutter Error when communicating with the Firebase Installations server API. HTTP response 
Shell :: how to use verifly in hardhat 
Shell :: mac ferdi install 
Shell :: Commit Changes With a Single Line Message or Through an Editor in git command 
Shell :: see unimported react comp. 
Shell :: chinese linux 
Shell :: ossec ubuntu 20 
Shell :: Multiple Sequential Commands in CRON Linux 
Shell :: cht sht .vim (config opts) 
Shell :: mac use multiple ssh keys for gihub 
Shell :: installing choclatey no adminstrative rights 
Shell :: Create Git respository 
Shell :: how to use firework command in the linux ternimal 
Shell :: how to hash a password in bash script 
Shell :: sftp client online linux remote 
Shell :: expo install safe area provider 
Shell :: pulish changes to firebase function 
Shell :: docker key for linux 
Shell :: shell remove pdf pages 
Shell :: git init bare initialize empty git repository 
Shell :: set the environment path variable for ffmpeg by running the following command: 
Shell :: bash rename different file names with zero padding 
Shell :: unit gitignore default-2021.dwlt 
Shell :: Disable Apache in a Django Bitnami Stack 
Shell :: turn off debug attach mode 
Shell :: remove files from git commit before push 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =