#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <utmpx.h>
#include <procfs.h>
typedef struct
{
int dev_major;
int dev_minor;
} dev_dat;
main(int argc,char *argv[])
{
char fname[256];
int fd;
psinfo_t pinfo;
int ret;
dev_dat dev;
struct utmpx ut,*utp;
sprintf(fname,"/proc/%d/psinfo",atoi(argv[1]));
fd = open(fname,O_RDONLY);
ret= read(fd,&pinfo,sizeof(pinfo));
printf("args=%s/n",pinfo.pr_psargs);
memcpy(&dev,&(pinfo.pr_ttydev),8);
if (dev.dev_major!=24)
{
printf("no tty/n");
exit(-1);
}
memset(&ut,0,sizeof(ut));
sprintf(ut.ut_line,"pts/%d",dev.dev_minor);
utp = getutxline(&ut);
if (!utp)
{
printf("no tty/n");
exit(-1);
}
printf("user=%s/n",utp->ut_user);
printf("tty=%s/n",utp->ut_line);
printf("host=%s/n",utp->ut_host);
}
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <utmpx.h>
#include <procfs.h>
typedef struct
{
int dev_major;
int dev_minor;
} dev_dat;
main(int argc,char *argv[])
{
char fname[256];
int fd;
psinfo_t pinfo;
int ret;
dev_dat dev;
struct utmpx ut,*utp;
sprintf(fname,"/proc/%d/psinfo",atoi(argv[1]));
fd = open(fname,O_RDONLY);
ret= read(fd,&pinfo,sizeof(pinfo));
printf("args=%s/n",pinfo.pr_psargs);
memcpy(&dev,&(pinfo.pr_ttydev),8);
if (dev.dev_major!=24)
{
printf("no tty/n");
exit(-1);
}
memset(&ut,0,sizeof(ut));
sprintf(ut.ut_line,"pts/%d",dev.dev_minor);
utp = getutxline(&ut);
if (!utp)
{
printf("no tty/n");
exit(-1);
}
printf("user=%s/n",utp->ut_user);
printf("tty=%s/n",utp->ut_line);
printf("host=%s/n",utp->ut_host);
}