Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/utility/program/raise"

From cppreference.com
< cpp‎ | utility‎ | program
(+std::)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{cpp/title| raise}}
 
{{cpp/title| raise}}
{{cpp/utility/program/sidebar}}
+
{{cpp/utility/program/navbar}}
 
{{ddcl | header=csignal |
 
{{ddcl | header=csignal |
 
int raise( int sig );
 
int raise( int sig );
 
}}
 
}}
  
Sends signal sig to the program. The signal handler, specified using {{rlpf|signal}} is invoked.
+
Sends signal sig to the program. The signal handler (specified using the {{lc|std::signal()}} function) is invoked.
  
If the user-defined signal handling strategy is not set using {{rlpf|signal}} yet, it is implementation-defined whether the signal will be ignored or default handler will be invoked.  
+
If the user-defined signal handling strategy is not set using {{lc|std::signal()}} yet, it is implementation-defined whether the signal will be ignored or default handler will be invoked.  
  
 
===Parameters===
 
===Parameters===
{{param list begin}}
+
{{par begin}}
{{param list item | sig | the signal to be sent. It can be an implementation-defined value or one of the following values:
+
{{par | sig | the signal to be sent. It can be an implementation-defined value or one of the following values:
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/utility/program/dcl list SIGABRT}}
+
{{dsc inc | cpp/utility/program/dsc SIG_types}}
{{dcl list template | cpp/utility/program/dcl list SIGFPE}}
+
{{dsc end}}
{{dcl list template | cpp/utility/program/dcl list SIGILL}}
+
{{dcl list template | cpp/utility/program/dcl list SIGINT}}
+
{{dcl list template | cpp/utility/program/dcl list SIGSEGV}}
+
{{dcl list template | cpp/utility/program/dcl list SIGTERM}}
+
{{dcl list end}}
+
 
}}
 
}}
{{param list end}}
+
{{par end}}
  
 
===Return value===
 
===Return value===
Line 29: Line 24:
 
{{example
 
{{example
 
  |
 
  |
 +
| p=true
 
  | code=
 
  | code=
 +
#include <csignal>
 +
#include <iostream>
 +
 +
void signal_handler(int signal)
 +
{
 +
    std::cout << "Received signal " << signal << '\n';
 +
}
 +
 +
int main()
 +
{
 +
    // Install a signal handler
 +
    std::signal(SIGTERM, signal_handler);
 +
 +
    std::cout << "Sending signal " << SIGTERM << '\n';
 +
    std::raise(SIGTERM);
 +
}
 
  | output=
 
  | output=
 +
Sending signal 15
 +
Received signal 15
 
}}
 
}}
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/utility/program/dcl list signal}}
+
{{dsc inc | cpp/utility/program/dsc signal}}
{{dcl list end}}
+
{{dsc see c | c/program/raise}}
 +
{{dsc end}}
  
 +
[[de:cpp/utility/program/raise]]
 +
[[es:cpp/utility/program/raise]]
 
[[fr:cpp/utility/program/raise]]
 
[[fr:cpp/utility/program/raise]]
 +
[[it:cpp/utility/program/raise]]
 
[[ja:cpp/utility/program/raise]]
 
[[ja:cpp/utility/program/raise]]
 +
[[pt:cpp/utility/program/raise]]
 +
[[ru:cpp/utility/program/raise]]
 
[[zh:cpp/utility/program/raise]]
 
[[zh:cpp/utility/program/raise]]

Latest revision as of 07:53, 15 August 2013

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)
 
 
Defined in header <csignal>
int raise( int sig );

Sends signal sig to the program. The signal handler (specified using the std::signal() function) is invoked.

If the user-defined signal handling strategy is not set using std::signal() yet, it is implementation-defined whether the signal will be ignored or default handler will be invoked.

Contents

[edit] Parameters

sig - the signal to be sent. It can be an implementation-defined value or one of the following values:
defines signal types
(macro constant) [edit]


[edit] Return value

0 upon success, non-zero value on failure.

[edit] Example

#include <csignal>
#include <iostream>
 
void signal_handler(int signal)
{
    std::cout << "Received signal " << signal << '\n';
}
 
int main()
{
    // Install a signal handler
    std::signal(SIGTERM, signal_handler);
 
    std::cout << "Sending signal " << SIGTERM << '\n';
    std::raise(SIGTERM);
}

Possible output:

Sending signal 15
Received signal 15

[edit] See also

sets a signal handler for particular signal
(function) [edit]
C documentation for raise