s_man
s_man

Reputation: 21

Catching a signal for a program

Are there any ways to catch a signal for a program where you don't have access to source code of the program. Is having a signal handler the only way?

Upvotes: 2

Views: 1166

Answers (1)

Amit Singh
Amit Singh

Reputation: 127

trap command traps the signals and other events.

  • Format: trap command signal_list
  • Example: Clean txt files from /tmp whenever signals(2,15)
# vim my_script.sh
    trap "{ /usr/bin/rm -r "/tmp/*.txt" }" SIGINT SIGTERM ERR EXIT

Upvotes: 3

Related Questions