win32-process

Get the Cpu usage of each process from wmi

一个人想着一个人 提交于 2019-11-30 20:14:00
I found many sources to get the cpu usage of each process. in general there are many ways to get the cpu usage of process . percentprocessortime from win32_perfformatteddata_perfproc_process performancecounter class in system.diagnostics by manual calculation Process class (by process.getcurrentprocess().totalprocessortime;) as said in here . FirstWay: For the remote process monitoring(my scenario is remote monitoring), the percentprocessortime always shows value 0 to 100+. this 100+ happens because of multiple processors in a system. it can be calculated by using percentprocessortime/

CreateProcess such that child process is killed when parent is killed?

浪尽此生 提交于 2019-11-30 11:33:37
Is there a way to call CreateProcess such that killing the parent process automatically kills the child process? Perhaps using Create Process Flags ? Edit The solution is to create a job object, place both parent and child in the job object. Whent he parent is killed the child is killed. I got the code from here: Kill child process when parent process is killed Take note of @wilx's comment about inherited handles. wilx Using jobs as Neil says is IMHO the best way. You can make the child processes get killed when the job owning process dies by setting JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE on the

Kill process and sub-processes in Ruby on Windows

不羁的心 提交于 2019-11-29 19:52:42
问题 Currently I'm doing this in one command prompt require 'win32/process' p = Process.spawn("C:/ruby193/bin/bundle exec rails s") puts p Process.waitpid(p) and then in another require 'win32/process' Process.kill(1,<p>) The problem is that the process I spawn (the Rails server in this case) spawns a chain of sub-processes. The kill command doesn't kill them, it just leaves them orphaned with no parent. Any ideas how can I kill the whole spawned process and all its children ? 回答1: I eventually

CreateProcess such that child process is killed when parent is killed?

女生的网名这么多〃 提交于 2019-11-29 16:58:37
问题 Is there a way to call CreateProcess such that killing the parent process automatically kills the child process? Perhaps using Create Process Flags? Edit The solution is to create a job object, place both parent and child in the job object. Whent he parent is killed the child is killed. I got the code from here: Kill child process when parent process is killed Take note of @wilx's comment about inherited handles. 回答1: Using jobs as Neil says is IMHO the best way. You can make the child

DEF file syntax error in visual studio 2012

一个人想着一个人 提交于 2019-11-29 13:50:29
I have a vs project which wouldn't compile once I upgraded to visual studio 2012. Its a win32 dll project and it complains about the def file. This is the def file, LIBRARY test.dll VERSION 3.1.4.1 EXPORTS addNumbers @1 and this is the error I get when I compile the project in visual studio 2012 ultimate. Source.def(2): fatal error LNK1118: syntax error in 'VERSION' statement What is confusing me is that, this works perfectly fine with visual studio 2008 & 2010. Any idea what is going wrong here? Thanks Sunil VERSION 3.1.4.1 DEF files are old . Back in ye goode olde days, programmers only ever

Does WaitForSingleObject give up a thread's time slice?

社会主义新天地 提交于 2019-11-29 10:59:30
I'm making a win32 program in C. When you have multiple threads running, and one of the threads is waiting for an event (using WaitForSingleObject() for example), does that thread still get its full CPU time slice? Stated differently, does the operating system know that the thread doesn't need its time slice until one of the events is signalled? Yes -- the thread is blocked until whatever it's waiting on becomes signaled. The thread won't be scheduled to run while it's blocked, so other threads get all the CPU time. Note that time slices don't enter into it much though. A thread can give up

Win32, ReadFile from pipe block even after child terminated

可紊 提交于 2019-11-29 09:36:45
I have a simple program (in C) that create two child process, wait on an inherited pipe each, and put the output in a file. Everything works well, except that after some write/read cycle on the two pipe, when the child ends, the call to ReadFile block, waiting for data on the pipe. I use the following pattern: ... //create pipe1 CreatePipe(&hReadDup,&hWrite,&saAttr,0); DuplicateHandle(GetCurrentProcess(),hReadDup,GetCurrentProcess(),&hRead,0,FALSE,DUPLICATE_SAME_ACCESS); CloseHandle(hReadDup); si.cb = sizeof(si); si.dwFlags = STARTF_USESTDHANDLES; si.hStdOutput = hWrite; CreateProcess( NULL,

Why is RemoveDirectory function not deleting the top most folder?

荒凉一梦 提交于 2019-11-29 08:18:33
refer: codeguru.com/forum/showthread.php?t=239271 When using the function below to delete folders, all folders, subfolders and files are getting deleted except for the top most folder. Say for the path c:\folder1\folder2 every thing under folder2 is deleted except for folder2 . BOOL DeleteDirectory(const TCHAR* sPath) { HANDLE hFind; // file handle WIN32_FIND_DATA FindFileData; TCHAR DirPath[MAX_PATH]; TCHAR FileName[MAX_PATH]; _tcscpy(DirPath,sPath); _tcscat(DirPath,_T("\\")); _tcscpy(FileName,sPath); _tcscat(FileName,_T("\\*")); // searching all files int nRet = 0; hFind = FindFirstFile

timespec equivalent for windows

不羁岁月 提交于 2019-11-29 02:29:20
I am porting my application to windows from unix and I have run into a wall. In my application I need to find time in microseconds (the whole application heavily depends on it due to it being a high precision application). Previously I was using timespec structure, but windows contains no such thing. The command GetTickCount does not suffice because it returns time in milliseconds. I was also thinking of QueryPerformanceFrequency . Would anyone happen to know something that is as identical to timespec as possible? In the future I might even require nanoseconds too, which nothing I have

Win32 Named mutex not released when process crashes

早过忘川 提交于 2019-11-29 02:03:43
I have 2 processes (A, B) sharing the same mutex (using WaitForSingleObject / ReleaseMutex calls). Everything works fine, but when process A crashes, process B is humming along happily. When I restart process A, there's a deadlock. Deeper investigation reveals that process B can successfully call ReleaseMutex() twice after process A crashes. My interpretation: After process A crashes, the mutex is still locked, but ownership of the mutex transfers readily to process B (which is a bug). That's why it's humming along happily, calling WaitForSingleObject (getting WAIT_OBJECT_0 in return) and