try man getutxent - this should be on your system. It automatically opens a file:
/etc/utmp
/etc/utmpx or
/var/adm/wtmp
/etc/utmp may not exist depending on how you set up the system. If you disabled any accounting, then it may not exist.
Also try using popen and a shell script - I just made up a function foo() - you get to change it and the command it uses:
Code:
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
pid_t foo(char *pid_to_find)
{
char cmd[296]={0x0}; /* 40 + 256 */
char tmp[256]={0x0};
FILE *in=NULL;
int retval=0;
pid_t the_pid_I_found=0;
snprintf(cmd,sizeof(cmd)-40,
"ps -ef | grep %s | awk '{print $2}'",pid_to_find);
in=popen(cmd, "r");
if(in==NULL)
{
perror("Shell execution error");
exit(EXIT_FAILURE);
}
while(fgets(tmp,4096,in)!=NULL)
{
the_pid_I_found=atol(tmp);
break;
}
retval=pclose(in);
return the_pid_I_found;
}