Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8862157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:39:39+00:00 2026-06-14T15:39:39+00:00

I am working on Solaris. I know that if there is a process running,

  • 0

I am working on Solaris.

I know that if there is a process running, there is a file called /proc/<PID>/status, where <PID> is the process id, and it contains a field called state.

As an example, I used my shell process:

> ps
   PID TTY         TIME CMD
 18671             0:01 tcsh

whose process id is 18671.

I had written a simple C program for extracting that information:

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/procfs.h>
#include <sys/fcntl.h>

static void get_status (pid_t pid)
{
  char procpath[100];
  char buf[100];
  int pfd;
  char State[100];
  char Name[100];
  prstatus_t * pms;
  FILE *proc;


    sprintf(procpath, "/proc/%d/status", pid);

    proc = fopen(procpath,"r");
    if (proc) {
        printf("Open Successful\n");
        fgets(buf,256,proc); sscanf(buf,"Name:\t%s",Name);
        fgets(buf,256,proc); sscanf(buf,"State:\t%c",State);
       }
    printf("%s",Name);
    printf("%s",State);
}

int main(int argc, char **argv)
{
    get_status(18671);

}

It doesn’t produce any output:

> ./a.out
Open Successful
> 

The online material for procfs says that we can simply do a cat on proc/<pid>/status and check the state of the process.

But in my case it’s a binary file. I never saw it mentioned anywhere that it is binary.

Is there a way where I could use a simple C program to get the state of the current process?

A C++ solution would also be acceptable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:39:40+00:00Added an answer on June 14, 2026 at 3:39 pm

    This is the struct you should read out of /proc/pid/status:

    typedef struct pstatus {
            int     pr_flags;       /* flags (see below) */
            int     pr_nlwp;        /* number of active lwps in the process */
            pid_t   pr_pid;         /* process id */
            pid_t   pr_ppid;        /* parent process id */
            pid_t   pr_pgid;        /* process group id */
            pid_t   pr_sid;         /* session id */
            id_t    pr_aslwpid;     /* historical; now always zero */
            id_t    pr_agentid;     /* lwp id of the /proc agent lwp, if any */
            sigset_t pr_sigpend;    /* set of process pending signals */
            uintptr_t pr_brkbase;   /* address of the process heap */
            size_t  pr_brksize;     /* size of the process heap, in bytes */
            uintptr_t pr_stkbase;   /* address of the process stack */
            size_t  pr_stksize;     /* size of the process stack, in bytes */
            timestruc_t pr_utime;   /* process user cpu time */
            timestruc_t pr_stime;   /* process system cpu time */
            timestruc_t pr_cutime;  /* sum of children's user times */
            timestruc_t pr_cstime;  /* sum of children's system times */
            sigset_t pr_sigtrace;   /* set of traced signals */
            fltset_t pr_flttrace;   /* set of traced faults */
            sysset_t pr_sysentry;   /* set of system calls traced on entry */
            sysset_t pr_sysexit;    /* set of system calls traced on exit */
            char    pr_dmodel;      /* data model of the process (see below) */
            char    pr_pad[3];
            taskid_t pr_taskid;     /* task id */
            projid_t pr_projid;     /* project id */
            int     pr_nzomb;       /* number of zombie lwps in the process */
            zoneid_t pr_zoneid;     /* zone id */
            int     pr_filler[15];  /* reserved for future use */
            lwpstatus_t pr_lwp;     /* status of the representative lwp */
    } pstatus_t;
    

    Note it’s defined in header file procfs.h. Declare a pstatus_t variable and read sizeof(pstatus_t) bytes into that variable.

    Tip: Also not available through ls, you can also use /proc/self/psinfo to read psinfo of self process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a KornShell (ksh) script running on a Solaris server that
I am working on Solaris and working on a script that turns on any
Is there anyone out there that is currently deploying rails applications on a solaris
I'm working on a C++ application on Solaris 11 that needs to read the
I've got a script in sh under Solaris 5.8 that isn't working as expected
I am working on different platforms (Solaris/Windows). I need to create a File object
I'm working on a solaris box. How do I go about deleting all files
On a Solaris 5.8 machine, I have the following code: [non-working code] char *buf;
Working with an undisclosed API, I found a function that can set the number
Working with JSF 2.0 (and Primefaces), is there a way to fire an ActionListener

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.