20.6 Some Useful Commands

   

Two commands are very useful when dealing with processes and signals. These are the timex and trap commands. The timex command tells you about the amount of time used by a process or a group of processes, and the trap command is used to capture signals on your system.

The timex Command

The timex command is used to report process and system activity. This command can be used to calculate the time used by a command or set of commands. For example, to check user and system time used during the execution of the ll /etc command, use the following command.

 timex ll /etc 

At the end of the normal output of the ll command, you will find additional lines showing the time used by the process created by the ll command in user and system modes and its total (real) execution time. This output is shown here.

 real        0.13 user        0.04 sys         0.05 

You can use this command with your shell programs or with any other code to check their efficiency and how they load the system.

The trap Command

The trap command captures signals and takes an action if a particular signal is received. If the command is used without arguments, it lists current traps. Output of this command may look like the following.

 $  trap  trap -- 'echo '\''logout'\' EXIT $ 

This line shows that a trap for the EXIT signal is set and the echo logout command will be executed when you exit from the shell.

If you use the following command, it will not show you any output and will set a trap on the INT signal.

 trap 'ls /etc' INT 

After using this command, use the trap command without arguments to verify that a trap for the INT signal is set. You will see an output like the following.

 $  trap  trap -- 'ls /etc' INT trap -- 'echo '\''logout'\' EXIT $ 

Now send an INT signal by pressing the graphics/ctrlc.gif key combination. You will see that the ls /etc command is executed and a list of all files in the /etc directory is displayed. In this way, you can set any response with a signal. The DEBUG signal can be used to do something after every command. For example, the following command will cause the current directory to be displayed after every command.

 trap pwd DEBUG 

All traps that are set once remain effective for the life cycle of your shell. Traps can be changed by setting a new trap value. For example, the trap for the DEBUG signal will be changed with the following command.

 trap date DEBUG 

Now the date and time will be displayed after every command. A trap value can be deleted if you use a null string with the trap command. The following command will stop displaying anything after every command.

 trap "" DEBUG 

Traps are very useful if you want to capture an event in your system. Setting a trap on a particular signal, for example, can inform you about a system event via email.


   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net