gpt4 book ai didi

检查进程是否正在 HP NonStop OSS Tandem 中运行

转载 作者:行者123 更新时间:2023-11-30 17:06:23 25 4
gpt4 key购买 nike

我有进程名称,想检查进程是否正在 HP NonStop OSS 中运行。我创建了小型 C 演示,但从 Guardian PROCESS_GETINFO_ 过程中收到错误。错误编号为 3。下面是我的代码。你能告诉我有什么问题吗?

#include <cextdecs.h(PROCESS_GETINFO_)>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

short getProcess(const char*);

enum ZSYSValues
{
ZSYS_VAL_LEN_PROCESSDESCR = 33
} ;

int main() {

const char* processName = "myProcess";
short status = getProcess(processName);

printf("status = %d", status);


return 0;

}


short getProcess(const char* processName) {

short error = 9;
short length = 20;
short maxLength = ZSYS_VAL_LEN_PROCESSDESCR;

/* error: 0 - found; 4 - not found, otherwise - error*/
error = PROCESS_GETINFO_ ( /* *processhandle */
,(char*) processName
,maxLength
,&length
,/* *priority */
,/* *mom’s-processhandle */
,/* *hometerm */
,/* maxlen */
,/* *hometerm-len */
,/* *process-time */
,/* *creator-access-id */
,/* *process-access-id */
,/* *gmom’s-processhandle */
,/* *jobid */
,/* *program-file */
,/* maxlen */
,/* *program-len */
,/* *swap-file */
,/* maxlen */
,/* *swap-len */
,/* *error-detail */
,/* *proc-type */
,/* *oss-pid */
,/* timeout */ );

printf("error = %d", error);

switch(error) {
case 0: return 1; /* found */
case 4: return 0; /* not found */
}
return -1; /* error */
}

最佳答案

Reference Manual

尝试这个版本:

#include <cextdecs.h(PROCESS_GETINFO_)>
#include <cextdecs(FILENAME_TO_PROCESSHANDLE_)>

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

short getProcess(const char *filename);

int main()
{
short status;

/* Change $XYZ to filename desired */
status = getProcess("$XYZ");

printf("status = %d", status);

return 0;
}

/* Get process by filename */
short getProcess(const char *filename)
{
short error = FEOK;
short length;
short processHandle[10] = { 0 };

error = FILENAME_TO_PROCESSHANDLE_(filename, strlen(filename), &processHandle);
if (error != FEOK) {
printf("error = %d", error);
return -1;
}

/* error: 0 - found; 4 - not found, otherwise - error*/
error = PROCESS_GETINFO_(
processHandle /* Process handle of process we want - Input */
, /* proc-fname */
, /* proc-fname-maxlen */
, /* proc-fname-len */
, /* priority */
, /* mom’s-processhandle */
, /* hometerm */
, /* maxlen */
, /* hometerm-len */
, /* process-time */
, /* creator-access-id */
, /* process-access-id */
, /* gmom’s-processhandle */
, /* jobid */
, /* program-file */
, /* maxlen */
, /* program-len */
, /* swap-file */
, /* maxlen */
, /* swap-len */
, /* error-detail */
, /* proc-type */
, /* oss-pid */
, /* timeout */
);

printf("error = %d", error);

switch (error) {
case 0:
return 1; /* found */
case 4:
return 0; /* not found */
}
return -1; /* error */
}

编辑:添加了一个使用文件名来处理句柄的示例。我找不到任何有关按名称获取进程的信息。

关于检查进程是否正在 HP NonStop OSS Tandem 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34755795/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com