How can I know the number of current users in the system?
It depends whether you're looking for an idea of who's on, or you want a definitive count. The lattter is basically almost impossible. What if a logged-in user nohups two xterms to different X-servers, then logs out - how many people are logged in? I've spent a hell of a long time working on this on AIX for a certain German bank, and the bottom line is that it can't be done. What is 'logged on' anyway? Someone running bash or ksh, that's cool, but what about someone running /home/fred/myprog? Is it a shell?
Basically once Unix went beyond serial terminals connected to dumb serial ports, we lost the ability to track users.
Nik
Quoted 4 lines
Hmmm, you should be able to count the number of pty's and tty's. Every logged in user is attached to some sort of getty whose parent is the init task (1). That might be a basis for a count.