Creating uniquely named log files with details of running processes (TASKLIST)

Thanks to Scott Moore (at LoadTester.com) for the idea behind this article and to the owners of DOStips.com for their article on DOS string manipulation which I used to get the string concatenation right.

When running performance tests or any kind of performance analysis it can be useful to know the processes running on a PC or server which are consuming resources. The Windows command TASKLIST gives a list of currently running processes (basically a text based version of what the Task Manager process tab shows you).

TASKLIST screenshot

By piping the output of this file to a text file you can save details of the running processes for later analysis.

Scott’s article described a batch file which you could run before and after certain events such as batch processing or performance tests to create uniquely named log files containing the TASKLIST information. I had some difficulty getting his time and date stamps to work, possibly due to the timezone settings in Windows which “regionalise” the date and time environment variables. I’ve modified his original batch file to this one below which seems to work on UK PCs running Windows 7, Windows Vista and Windows XP.

Sample Code

for /f “tokens=1-3 delims=/ ” %%d in (“%date%”) do set d=%%d-%%e-%%f

for /f “tokens=1-3 delims=:” %%d in (“%time%”) do set t=%%d%%e

set timestr=%d:~6,4%%d:~3,2%%d:~0,2%-%t:~0,2%%t:~2,2%

tasklist /FO CSV > TASKLIST_Logfile_%timestr%.csv

 

This creates a CSV file named TASKLIST_Logfile_YYYYMMDD-HHMM.csv formatted like the sample below.


Sample Output

“Image Name”,”PID”,”Session Name”,”Session#”,”Mem Usage”

“System Idle Process”,”0″,”Services”,”0″,”24 K”

“System”,”4″,”Services”,”0″,”95,672 K”

“smss.exe”,”272″,”Services”,”0″,”64 K”

“csrss.exe”,”408″,”Services”,”0″,”2,484 K”

“csrss.exe”,”484″,”Console”,”1″,”73,224 K”

“wininit.exe”,”496″,”Services”,”0″,”172 K”

“avgchsva.exe”,”508″,”Services”,”0″,”25,816 K”

 

 

Google Chromium OS – first impression

I thought that I’d have a quick look at Google Chromium OS. I’m not sure that it’s living up to the hype yet.

Where did I get it?
So far it’s only available as a VMware or Sun Virtual box download. I downloaded both the VMWare .vmdk file and the Sun Virtual box .vdi files from http://gdgt.com/. I had problems with my VMWare installation so I thought I’d try it in Sun Virtual Box. I’m running Sun Virtual Box on a Windows 7 64-bit host.

First impressions
The Sun Virtual Box image doesn’t boot properly and only boots to a black screen. Because Sun Virtual Box can support VMWare images, I thought that I’d try the .vmdk file. I noticed other posts which recommend configuring the network in “bridged mode” and running Virtual Box with administrator credentials. I did both of these things and Chromium booted first time. I was presented with a simple login screen.
At this point I entered my gmail account details. The image uses a US keyboard so the @ symbol is “Shift-2”.

After login you see a very simple browser screen with your Google mail and Google calendar tabs. Other tabs can be opened and it can be used as s simple browser. At the moment, I can’t see much value in it, but couple it with some nicer fonts and the ability to save/sync your Google Docs to the local hard disk of a laptop/netbook or USB key and it could have potential.

What’s the point?

Perhaps one use could be for students to all be issued with their own OS and Docs on a USB key, all Docs are backed up centrally, but they could take their key to any machine and boot from it to get the same locked-down experience wherever they work.

Alternatively, banks could issue secure keys for online banking containing an OS that can only access the bank’s online banking site. This could greatly reduce online account fraud by only granting access to web based banking to people who have a physical device (encrypted USB key), know the password for the key as well as the online account password.

Google Chromium screenshot

UNIX command reference


Environment Control

Command                     Description
cd d                             Change to directory d
mkdir d                        Create new directory d
rmdir d                         Remove directory d
mv f1 [f2...] d               Move file f to directory d
mv d1 d2                      Rename directory d1 as d2
passwd                         Change password
alias name1 name2       Create command alias (csh/tcsh)
alias name1="name2"    Create command alias (ksh/bash)
unalias name1[na2...]    Remove command alias na
ssh nd                          Login securely to remote node
exit                              End terminal session
setenv name v              Set env var to value v (csh/tcsh)
export name="v"           Set environment variable to value v (ksh/bash)


Output, Communication, & Help

Command                     Description
lpr -P printer f               Output file f to line printer
lp -d printer f                Output file f to line printer
script  [f]                      Save terminal session to f
exit                              Stop saving terminal session
mailx username             Send mail to user
man name                     Unix manual entry for name


Process Control

Command                     Description
CTRL/c *                      Interrupt processes
CTRL/s *                      Stop screen scrolling
CTRL/q *                      Resume screen output
sleep n                         Sleep for n seconds
jobs                             Print list of jobs
kill %                           Kill job n
ps                                Print process status stats  
kill  -9 n                       Remove process n
CTRL/z *                      Suspend current process
stop  %n                      Suspend background job n
cmmd&                        Run cmmd in background
bg  [%n]                      Resume background job n
fg  [%n]                       Resume foreground job n
exit                              Exit from shell


Environment Status

Command                     Description
ls  [d]  [f...]                  List files in directory
ls -1  [f...]                    List files in detail
alias  [name]                Display command aliases
printenv  [name]           Print environment values
quota                           Display disk quota
date                             Print date & time
who                              List logged in users
whoami                        Display current user
finger  [username]        Output user information
chfn                             Change finger information
pwd                              Print working directory
history                          Display recent commands
! n                               Submit recent command n


File Manipulation

Command                     Description
vi  [f]                            Vi fullscreen editor
emacs  [f]                     Emacs fullscreen editor
ed  [f]                          Text editor
wc  f                             Line, word, & char count
cat  f                            List contents of file
more  f                         List file contents by screen
cat f1 f2 >f3                  Concatenates f1 & f2 into f3
chmod mode f               Change protection mode of f
cmp f1 f2                      Compare two files
cp f1 f2                         Copy file f1 into f2
sort f                            Alphabetically sort f
split  [-n]  f                   Split f into n-line pieces
mv f1  f2                      Rename file f1 as f2
rm f                             Delete (remove) file f
grep 'ptn'  f                  Outputs lines that match ptn
diff f1 f2                       Lists file differences
head f                          Output beginning of f
tail f                            Output end of f


Abbreviations used in this document

CTRL/x       hold down control key and press x
d               directory
env            environment
f                filename
n               number
nd             computer node
prtr            printer
ptn            pattern
var            variable
[y/n]         yes or no
[]             optional arg
...             list