0

I have process name and would like to check if process is running in HP NonStop OSS. I created small C demo, but got error from Guardian PROCESS_GETINFO_ procedure. Error number is 3. Below is my code. Could you please tell me what is the problem.

#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 */
}
uril
  • 11
  • 6

1 Answers1

1

Reference Manual

Try this version:

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

Edit: Added an example using filename to process handle. I couldn't find any information reguarding getting a process by name.

x64architecture
  • 399
  • 1
  • 7
  • Thank you! Could you please tell me why the third parameter is sizeof(processName)? On Tandem sizeof(processName) is 4 bytes, because is pointer. After I implemented your version of code I got the same error = 3. I have changed third parameter to ZSYS_VAL_LEN_PROCESSDESCR and got error = 0, which mean is found process name. Problem is I defined process name equals NULL char processName[ZSYS_VAL_LEN_PROCESSDESCR] = {NULL}; but still got error = 0; I am confused. There is no running process name which is NULL and why did I get error = 0(it should be not found). Did I miss something? – uril Jan 13 '16 at 23:35
  • My first understanding was I will supply const char* process name to Guardian procedure PROCESS_GETINFO_ which will reply if process is running or not. After getting reply from you(Thank you very much!) and reading more carefully Guardian manual I understand my error.But still I have a problem. For example I supply process name that is not running, I get response that is found(error = 0). char processName[33] = "process is not running"; error = PROCESS_GETINFO_ ( ,processName / ,ZSYS_VAL_LEN_PROCESSDESCR ,&length – uril Jan 14 '16 at 21:56
  • Your right the sizeof was incorrect, I wasn't thinking. You need to get the process handle of the process you want to know the status of (e.g. use `FILENAME_TO_PROCESSHANDLE_`) by default the proccess handle is that of the calling process (your program) I can update with an example if you want. – x64architecture Jan 14 '16 at 23:55
  • Could you please give me an example? – uril Jan 15 '16 at 15:14
  • THANK YOU VERY MUCH! IS WORKING! – uril Jan 15 '16 at 20:20