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

时间:2016-01-12 23:33:32

标签: c hp-nonstop

我有进程名称,并希望检查进程是否在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 */
}

1 个答案:

答案 0 :(得分:0)

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 */
}

编辑:添加了一个使用filename来处理句柄的示例。我无法找到任何关于按名称获取流程的信息。