The w command show who is currently logged in to the system and from where. As Linux gains more and more desktop usage one might wonder how useful this command could be in an environment that particularly caters to a one person per use system. While w is critical in a server environment where you may have multiple system administrators performing various functions and a need to know who may be working on the machine before bringing down the server or a service, w still manages to display some very crucial information that is also valuable to the single desktop user environment.
The output of w:
Displays the following information in the header:
- Time: 16:03:44
- Uptime: 9 days, 19 hours 22 minutes
- How many users are logged in: 8 users
- Load Average: 1.05, 0.82, 0.69
This is followed by information on each person logged in and what process he or she is currently running:
- Login name: dann
- tty logged into: tty
- remote host id:
- Login time (when the user logged in) – 07Jun12
- How long the user has been idle: 9days
- JCPU : Total time used by user since login: 1:08
- PCPU: CPU time used by the current running process: 0.00s
- Command line of the current process: xinit …..
The header information is pretty straight forward except for load average. Load average is a very useful metric and appears not only in this command but also in top (which we will be covering in a future episode). Load average is broken into 3 values: Past 1 minute, past 5 minutes, and past 15 minutes. What this average relates is how often processes are waiting for CPU time.
Load average is often explained using a traffic analogy where the cpu is the highway and the load average is a value representing the cars waiting to get on the highway from an on ramp. When there are no cars on the on ramp, that means there is no backup and processes are not having to wait for cpu time. As CPU utilization increases more cars start to backup on the on ramp and thus load average increases. The more cars that are backed up, the greater the load average and the longer processes have to wait for CPU time.
Ideally load average should be below 1.0 per processor. If your load average is exactly 1 that means the cpu is running at full capacity with no processes waiting. Above 1 could indicate a problem and processes are having to wait for cpu time.
Be careful with how you interpret load averages, you cannot just rely on the load average of the past minute to indicate whether there is a problem or not. Hence the reason the past 5 minutes and past 15 minutes are also represented. The latter two values provide more of a current profile that just the past minute. This allows you to observe the performance of your system over a short period of time and can weed out false alarms.
Lets say you started a game or were compiling a program and saw your load average spike to over 1.35 the past minute. Chances are your 5 and 15 minute averages saw a more modest bump in load averages but nothing to indicate there is a probelm, after all you ran a pretty intensive task.
On the other hand, if you start seeing values over .70 in two or more of these columns over time, you may want to start ferreting out the culprit as this is a pretty good indication there is a problem. Again, be aware of what is going on. If you are rendering a movie, this may be normal load averages for such an intensive task. But if you are running a web server this could indicate your system resources are getting close to being taxed and you may want to start beefing up your machine.
Note that the emphasis was placed on 1 processor. Many systems run more than one processor or have multiple cores per processor. These extra processors need to be taken into account when observing load averages. Thus the traffic analogy continues and we can equate each processor to a lane of traffic. So now in a dual core system where you have the equivalent of 2 processors, a load average of 1 is not alarming. A load average of 1.7 should start to raise eyebrows and a load average of 2 means both processors are running processes to the max. Getting over 2.15 means you probably need to start paying attention to what is going on. Should this trend continue over a period of time and start to grow, you need to fix the problem fast.
To summarize with another way to look at load averages, if the load average is under 1.0 that means your processor is more than capable of handling the load you have been putting on it. At 1.0 means your CPU is maxed but handling the load as necessary. A load average of 2 means that ideally you would need at least twice the cpu capacity to handle the load average your system has been experiencing. At 5.0 you are 5 times above our CPU’s capacity. Again, this is a very rough analogy, not completely accurate, but close enough to give you and idea of what to look out for.
There are a few switches you can pass to the w command. The -h or –no-header option will display only the users and process information. The -s or –short displays only the header, users and processes. It omits the JCPU and PCPU information.
The -f or –from switch toggles on displaying the from remote host field. This field will show up between the TTY and Login@ fields:
Will show only the processes pertaining to the username specified. The header will remain unaltered.
- What is JCPU and PCPU
- Understanding Load Average Scout App Blog
- Examining Load Average – Linux Journal
If the video is not clear enough view it off the YouTube website and select size 2 or full screen. Or download the video in Ogg Theora format:
- Episode 009 – w from Internet Archive
Thank you very much.
- OGG audio file from Hacker Public Radio
- Speex audio file from Hacker Public Radio
- MP3 audio file from Hacker Public Radio