Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not open process: The parameter is incorrect. (error 87) #9

Open
vinoakash opened this issue Aug 26, 2023 · 5 comments
Open

Could not open process: The parameter is incorrect. (error 87) #9

vinoakash opened this issue Aug 26, 2023 · 5 comments

Comments

@vinoakash
Copy link

Hi All,

I am trying to use the package resusage, and I am getting the below error message, googled for this error and tried all the solution provided still facing the same issue, hence requesting your help.

Solution Provided
dism.exe /image:C: /cleanup-image /revertpendingactions dism.exe /online /cleanup-image /startcomponentcleanup
Error
std.windows.syserror.WindowsException@resusage\common.d(25): Could not open process: The parameter is incorrect. (error 87)

From,
Vino.B

@FreeSlave
Copy link
Owner

FreeSlave commented Aug 26, 2023

Hi. Probably the process doesn't exist by the time you request the information. E.g. it exits too soon.
The message is somewhat misleading but that's what WinAPI returns. Need more context on what's happening in your app.
It's also possible that you're providing something else than process id to the library API. Make sure it's a process id and not, for example, a thread id.

@vinoakash
Copy link
Author

Hi All,

Please find the details, we are trying to capture the CPU and Memory utlization of a process id where the process is created by below

Program

import resusage.memory;
import resusage.cpu;

CPUWatcher cpuInfo;

result = std.process.pipeProcess(_program ~ _args, redirect, _env, _config, _workdir);
result = std.process.pipeShell(_command, redirect, _env, _config, _workdir, _shellPath);

int spwanPID = (result.pid).processID; 

cpuInfo = new ProcessCPUWatcher(spwanPID); 
auto memInfo = processMemInfo(spwanPID);

writeln("[MEMORY]:  %s bytes\t".format(memInfo.usedRAM));
writeln("[CPU]:  %s%%\t".format(cpuInfo.current()));

The above code works file for the process which is created by std.process.pipeProcess where same is failing for the process created by std.process.pipeShell.

cpuInfo = new ProcessCPUWatcher(spwanPID);   // this is child process id

if we replace this with the parent process id it works , the same do not work using child process id, we actually need the CUP and Memory of the child process in both the case.(std.process.pipeProcess , std.process.pipeShell)

cpuInfo = new ProcessCPUWatcher(thisProcessID);  // parent process id

@FreeSlave
Copy link
Owner

I couldn't reproduce it.

I wrote the following program:

import std.stdio;
import resusage.memory;
import resusage.cpu;
import std.process;
import std.format;

void main()
{
    CPUWatcher cpuInfo;
    string appPath = "testd.exe";
    //auto result = std.process.pipeProcess([appPath]);
    auto result = std.process.pipeShell(appPath);

    int spwanPID = (result.pid).processID; 
    writeln("Pid: ", spwanPID);

    cpuInfo = new ProcessCPUWatcher(spwanPID); 
    auto memInfo = processMemInfo(spwanPID);

    writeln("[MEMORY]:  %s bytes\t".format(memInfo.usedRAM));
    writeln("[CPU]:  %s%%\t".format(cpuInfo.current()));
    
    wait(result.pid);
}

With testd.exe being another D program

int main()
{
    return 0;
}

If you provide reproducible case, I can look at it.

@vinoakash
Copy link
Author

Please try the below code

`
import core.time : minutes, seconds;
import resusage.cpu;
import resusage.memory;
import std.container.array;
import std.conv: to;
import std.datetime.stopwatch : StopWatch, AutoStart;
import std.datetime.systime: Clock, SysTime;
import std.process;
import std.range: empty;
import std.stdio: writeln;

void main () {
CPUWatcher cpuInfo;
SysTime start, end;
long duration;
ProcessPipes result;
Array!string output; Array!string errors;

auto sw = StopWatch(AutoStart.no);
sw.start();
start = Clock.currTime(); 

result = std.process.pipeShell(escapeShellCommand(["whoami", "/?"]), Redirect.stdout | Redirect.stderr);
	
int spwanPID = (result.pid).processID;
cpuInfo = new ProcessCPUWatcher(spwanPID); 
auto memInfo = processMemInfo(spwanPID); 
	
result.stdout.flush(); result.stderr.flush();
foreach (line; result.stdout.byLine) if(!empty(line)) { output.insertBack(line.to!string); }
foreach (line; result.stderr.byLine) if(!empty(line)) { errors.insertBack(line.to!string); }

int exitCode = wait(result.pid);
scope(exit) { wait(result.pid); sw.stop(); }
end = Clock.currTime(); 
duration = sw.peek.total!"msecs";
writeln(memInfo.usedRAM);
writeln(cpuInfo.current());
writeln(output[]);
writeln();
writeln(errors[]);

}
`

@FreeSlave
Copy link
Owner

The process you're trying to get the information from has already exited when you request the cpu time info.
This library is for tracking long living processes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants