Trap Command Assignment Help

Assignment Help: >> Advanced Shell Scripts - Trap Command

The trap command

There are certain things which are not under the control of the program in during execution.

The user of the program might press the interrupt key or send a kill command to the process or the controlling terminal might become disconnected from the system. Within UNIX, any of these events could cause a signal to be sent to the process. When a process receives a signal is to terminate the default action.

A few times, the user might require taking some special action when a signal is received. The temporary data files remain if a program is creating temporary data files, and it is terminated through a signal. The user can modify the default action of the program by using the trap command.

Syntax

trap command-string signals

In the syntax the signals are one or more signals that are to be trapped

Command-string is one or more commands divided through semicolon that are to be executed whenever the signals are received.

Example

$ trap "rm /tmp/*$ ; exit " 1 2 15

The trap command informs the shell to remove the files which end with PID at the temporary directory and exit the program whenever signals 1,2 and 15 are received.

1956_trap command.png

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd