Skip navigation.
Home
The QNX Community Portal

View topic - Get processes states

Page 1 of 1

Get processes states

PostPosted: Tue Feb 17, 2015 10:27 am
by olivier_g
Hi

I want to obtain some processes states RECEIVE, DEAD, REPLY (like pidin)

I wrote some code
procfs_status my_status;
memset(&my_status, 0x0, sizeof (my_status));
sts = devctl( fd, DCMD_PROC_STATUS, &my_status, sizeof(my_status), NULL);

devctl return state is OK but my_status.state is always 0 which mean DEAD

Where is the problem ?

Thank

Olivier

Re: Get processes states

PostPosted: Tue Feb 17, 2015 8:41 pm
by Tim
We need to see the rest of your code. Specifically how you are filling out your fd value.

Here's some sample code from the QNX doc's. Your code should look something like this replacing DCMD_PROC_MAPDEBUG_BASE with your DCMD_PROC_STATE.


Code: Select all
int
display_process_info(pid_t pid)
{
    char            buf[PATH_MAX + 1];
    int             fd, status;
    struct dinfo_s  dinfo;
    procfs_greg     reg;

    printf("%s: process %d died\n", progname, pid);

    sprintf(buf, "/proc/%d/as", pid);

    if ((fd = open(buf, O_RDONLY|O_NONBLOCK)) == -1)
        return errno;

    status = devctl(fd, DCMD_PROC_MAPDEBUG_BASE, &dinfo,
                    sizeof(dinfo), NULL);
    if (status != EOK) {
        close(fd);
        return status;
    }

    printf("%s: name is %s\n", progname, dinfo.info.path);

    /*
     * For getting other type of information, see sys/procfs.h,
     * sys/debug.h, and sys/dcmd_proc.h
     */
     
    close(fd);
    return EOK;
}


Tim

Re: Get processes states

PostPosted: Thu Feb 19, 2015 3:08 pm
by olivier_g
The entire code is

sprintf (paths, "/proc/%d/as", pid);

if ((fd = open (paths, O_RDONLY)) == -1)
{
printf("erreur open %s \n", paths);
return;
}

procfs_status my_status;
memset(&my_status, 0x0, sizeof (my_status));
sts = devctl( fd, DCMD_PROC_STATUS, &my_status, sizeof(my_status), NULL);
if (sts != EOK)
{
fprintf(stderr, "DCMD_PROC_STATUS pid %d errno %d (%s)\n", pid, errno, strerror (errno));
}
else
{
printf("DCMD_PROC_STATUS pid %d state %d priority %d\n",pid, my_status.state ,my_status.priority);
}
I iterate all the processes. sts is EOK but my_status.state is aways 0 (DEAD)

Re: Get processes states

PostPosted: Thu Feb 19, 2015 5:07 pm
by Tim
OK, I tried and got same results as you.

However I figured out pretty quickly that getting Process info isn't going to get you thread data. What you really want is

my_status.tid = 1;
devctl( fd, DCMD_PROC_TIDSTATUS, &my_status, sizeof(my_status), NULL);

That gets the individual thread info. I tried this and immediately got the state/priority fields etc for the threads in a process. So you need to change your call and iterate through the threads in each process by supplying the id (tid).

Tim