cancel
Showing results for 
Search instead for 
Did you mean: 

terminal idle time

SOLVED
Go to solution
raam narayan
Occasional Advisor

terminal idle time

hi there,

I am writing a C program to find the log info of the users who are currently logged in(precisely what who -u do).

I am able to get all the information except the idle time. I used getuts function for getting info. The man page says getuts allows fields like ut_id, ut_type, ut_tv(login time) etc.

Can any one suggest me how to find the idle time of users currenly logged in?

thanks
R
8 REPLIES
Hakki Aydin Ucar
Honored Contributor

Re: terminal idle time

I thought a very simple way, I hope it helps to you: issue the command;

who -uH |more

watch the IDLE field AND use manpage of who to find more . .
raam narayan
Occasional Advisor

Re: terminal idle time

use manpage of who to find more >>>>>>>>>>>>

Yes i've gone through it. It refers the following files: "/etc/inittab", "/etc/utmp", "/var/adm/wtmp", "/var/adm/wtmps".

To my knowledge who refers to database daemon "utmpd" for getting the log information.

and hp ux has given "getuts" for add/update/retrieve log data. thats how i came to know about 'getuts' in the first place and from getuts i couldnot get the idle time.
Dennis Handly
Acclaimed Contributor

Re: terminal idle time

>from getuts(3) I could not get the idle time.

Of course not. You get it from stat(2) on the device, st_atime.
Using tusc on who(1) would hint at this.
raam narayan
Occasional Advisor

Re: terminal idle time

Thanks Dennis. Will try that.

-R
raam narayan
Occasional Advisor

Re: terminal idle time

Dennis,

I tried to use stat(2). As it is asking for the file path i tried giving "/etc/utmp" "etc/utmpx" and "etc/utmps". None of them returned proper last access time.

Using tusc on who(1) would hint at this.>>>>>>

Can you please elaborate this?

Thanks,
-R
James R. Ferguson
Acclaimed Contributor
Solution

Re: terminal idle time

Hi Raam:

> I tried to use stat(2). As it is asking for the file path i tried giving "/etc/utmp" "etc/utmpx" and "etc/utmps". None of them returned proper last access time.

No, you want to stat() the device file given by ' ut_line' of the 'utmps' structure. Then compute the difference between the current epoch seconds and the 'st_atime' to determine the idle interval.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: terminal idle time

>I tried to use stat(2).

As JRF said, you need to look at the input device.

>>Using tusc on who(1) would hint at this.

>Can you please elaborate this?

If you use tusc on who, you can get hints what it does:
tusc -fp -ea -o tusc.out who -u

>JRF: you want to stat() the device file given by 'ut_line' of the 'utmps' structure.

That's exactly what who(1) does.
stat("/dev/pts/tc", 0x7fffe590) ..... = 0
time(NULL) .................. = 1255771999
raam narayan
Occasional Advisor

Re: terminal idle time

Thanks JRF and Dennis. Closing the thread.