diff options
author | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-27 16:07:43 +0000 |
---|---|---|
committer | dave <dave@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-27 16:07:43 +0000 |
commit | 1cac228f27101540bab674445caf0f2ffb933560 (patch) | |
tree | 1cf036e776b5248f820d5d4b2da6eda6641b23f8 /signal.c | |
parent | 339aae6c804f5a7ef4c6d8df61024187a65e4770 (diff) | |
download | ruby-1cac228f27101540bab674445caf0f2ffb933560.tar.gz ruby-1cac228f27101540bab674445caf0f2ffb933560.tar.xz ruby-1cac228f27101540bab674445caf0f2ffb933560.zip |
RDoc comments added by Elliott Hughes
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@5321 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'signal.c')
-rw-r--r-- | signal.c | 74 |
1 files changed, 74 insertions, 0 deletions
@@ -643,6 +643,34 @@ rb_trap_restore_mask() #endif } +/* + * call-seq: + * Signal.trap( signal, proc ) => obj + * Signal.trap( signal ) {| | block } => obj + * + * Specifies the handling of signals. The first parameter is a signal + * name (a string such as ``SIGALRM'', ``SIGUSR1'', and so on) or a + * signal number. The characters ``SIG'' may be omitted from the + * signal name. The command or block specifies code to be run when the + * signal is raised. If the command is the string ``IGNORE'' or + * ``SIG_IGN'', the signal will be ignored. If the command is + * ``DEFAULT'' or ``SIG_DFL'', the operating system's default handler + * will be invoked. If the command is ``EXIT'', the script will be + * terminated by the signal. Otherwise, the given command or block + * will be run. + * The special signal name ``EXIT'' or signal number zero will be + * invoked just prior to program termination. + * trap returns the previous handler for the given signal. + * + * Signal.trap(0, proc { puts "Terminating: #{$$}" }) + * Signal.trap("CLD") { puts "Child died" } + * fork && Process.wait + * + * produces: + * Terminating: 27461 + * Child died + * Terminating: 27460 + */ static VALUE sig_trap(argc, argv) int argc; @@ -681,6 +709,15 @@ sig_trap(argc, argv) #endif } +/* + * call-seq: + * Signal.list => a_hash + * + * Returns a list of signal names mapped to the corresponding + * underlying signal numbers. + * + * Signal.list #=> {"ABRT"=>6, "ALRM"=>14, "BUS"=>7, "CHLD"=>17, "CLD"=>17, "CONT"=>18, "FPE"=>8, "HUP"=>1, "ILL"=>4, "INT"=>2, "IO"=>29, "IOT"=>6, "KILL"=>9, "PIPE"=>13, "POLL"=>29, "PROF"=>27, "PWR"=>30, "QUIT"=>3, "SEGV"=>11, "STOP"=>19, "SYS"=>31, "TERM"=>15, "TRAP"=>5, "TSTP"=>20, "TTIN"=>21, "TTOU"=>22, "URG"=>23, "USR1"=>10, "USR2"=>12, "VTALRM"=>26, "WINCH"=>28, "XCPU"=>24, "XFSZ"=>25} + */ static VALUE sig_list() { @@ -748,6 +785,43 @@ init_sigchld(sig) #endif } +/* + * Many operating systems allow signals to be sent to running + * processes. Some signals have a defined effect on the process, while + * others may be trapped at the code level and acted upon. For + * example, your process may trap the USR1 signal and use it to toggle + * debugging, and may use TERM to initiate a controlled shutdown. + * + * pid = fork do + * Signal.trap("USR1") do + * $debug = !$debug + * puts "Debug now: #$debug" + * end + * Signal.trap("TERM") do + * puts "Terminating..." + * shutdown() + * end + * # . . . do some work . . . + * end + * + * Process.detach(pid) + * + * # Controlling program: + * Process.kill("USR1", pid) + * # ... + * Process.kill("USR1", pid) + * # ... + * Process.kill("TERM", pid) + * + * produces: + * Debug now: true + * Debug now: false + * Terminating... + * + * The list of available signal names and their interpretation is + * system dependent. Signal delivery semantics may also vary between + * systems; in particular signal delivery may not always be reliable. + */ void Init_signal() { |