DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Writing Deskshell commands

Signals

Signals provide a way of passing messages between two threads. Any thread can send a signal to any other thread using the kill command.

Signal handlers are defined in exactly the same way as functions, with names that must begin with sig.

When a thread receives a signal, the function with the same name as the signal is called, interrupting any other action that the thread is carrying out. When the function returns, the previous action continues. If no function has been defined, or inherited from parent threads, the signal is ignored.

For example, the following program shows how a signal can be used to give the user the option of canceling a lengthy compress operation:

   function sigstop
   {
      stop=true
   }
   

{ if yni Cancel? then kill sigstop $threadname(2) fi } &

stop=false for i in $dynamic_args do compress $i if $stop then exit fi done

This command compresses icons that are dropped onto a hypothetical compress icon. Before compressing any of the icons, it puts up a yni dialog box in the background to give the user the option of canceling the command at any time. If the user chooses Yes, the background thread sends the specially defined signal sigstop to its parent thread, $thread_name (2), and this has the effect of setting the variable stop to ``true''. The next time the if $stop ... line is read, the operation will be canceled.

See also:


Next topic: Standard signals
Previous topic: Executing actions within the same thread

© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 26 May 2005