I am trying to get the terminal information with /proc file system on AIX.
Sample program on AIX
#include <stdio.h>
#include <sys/procfs.h>
#include <sys/sysmacros.h>
#define DEVNO64 0x8000000000000000LL
#define DEVNORSV 0x4000000000000000LL
#define DEV64_valid(_devno) \
((((((dev64_t)(_devno)) & (DEVNO64 | DEVNORSV)) >> 62) == 4) ? 1 : 0)
#define ISDEV_VALID(dev) DEV64_valid(dev)
int main(int argc, char *argv[])
{
char statfilenm[32];
FILE *fp;
psinfo_t pinfo;
sprintf(statfilenm, "/proc/%d/psinfo", getpid());
fp = fopen(statfilenm, "r");
if (!fp)
return 0;
fread(&pinfo, sizeof(psinfo_t), 1, fp);
fclose(fp);
if(ISDEV_VALID((dev64_t)pinfo.pr_ttydev))
printf("\n %d", minor64((dev64_t)pinfo.pr_ttydev));
else
printf("\n Invalid device");
}
Above program is returning "Invalid device" output for all processes with valid terminal also
Like
PID TTY STAT TIME COMMAND
10683272 pts/0 A 0:00 xxxxxxxxxxxxxxx
PID TTY STAT TIME COMMAND
10617844 - A 0:00 xxxxxxxxx