本文整理汇总了C++中sigwait函数的典型用法代码示例。如果您正苦于以下问题:C++ sigwait函数的具体用法?C++ sigwait怎么用?C++ sigwait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigwait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: child
int child()
{
int shmid ,
chld_pid ;
char *cp;
int sig;
sigwait(&sigset, &sig);
chld_pid = getpid() ;
if ((shmid = shmget(key, SIZE, 0)) < 0) {
perror("shmget:child process");
tst_resm(TFAIL,
"Error: shmget: errno=%d, shmid=%d, child_pid=%d\n",
errno, shmid, chld_pid);
}
else {
#ifdef __ia64__
cp = (char *) shmat(shmid, ADDR1_IA, 0);
#elif defined(__ARM_ARCH_4T__)
cp = (char *) shmat(shmid, (void *) NULL, 0);
#elif defined(__mips__)
cp = (char *) shmat(shmid, ADDR1_MIPS, 0);
#else
cp = (char *) shmat(shmid, ADDR1, 0);
#endif
if (cp == (char *)-1) {
perror("shmat:child process");
tst_resm(TFAIL,
"Error: shmat: errno=%d, shmid=%d, child_pid=%d\n",
errno, shmid, chld_pid);
} else {
if (*cp != 'A') {
tst_resm(TFAIL,"child: not A\n");
}
if (*(cp+1) != 'B') {
tst_resm(TFAIL,"child: not B\n");
}
if (*(cp+2) != 'C') {
tst_resm(TFAIL,"child: not C\n");
}
if (*(cp+8192) != 0) {
tst_resm(TFAIL,"child: not 0\n");
}
}
}
tst_exit() ;
return(0);
}
示例2: main
int main(int argc, char* argv[])
{
try
{
// Check command line arguments.
if (argc != 5)
{
std::cerr << "Usage: http_server <address> <port> <threads> <doc_root>\n";
std::cerr << " For IPv4, try:\n";
std::cerr << " receiver 0.0.0.0 80 1 .\n";
std::cerr << " For IPv6, try:\n";
std::cerr << " receiver 0::0 80 1 .\n";
return 1;
}
// Block all signals for background thread.
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
// Run server in background thread.
std::size_t num_threads = boost::lexical_cast<std::size_t>(argv[3]);
http::server::server s(argv[1], argv[2], argv[4], num_threads);
boost::thread t(boost::bind(&http::server::server::run, &s));
// Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Wait for signal indicating time to shut down.
sigset_t wait_mask;
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
int sig = 0;
sigwait(&wait_mask, &sig);
// Stop the server.
s.stop();
t.join();
}
catch (std::exception& e)
{
std::cerr << "exception: " << e.what() << "\n";
}
return 0;
}
示例3: sig_handler_thd
static void * sig_handler_thd(void *data)
{
sigset_t *mask = data;
int ret, sig;
/* Blocks until one of the termination signals is received */
do {
ret = sigwait(mask, &sig);
} while (ret == EINTR);
quit_all(ret);
return NULL;
}
示例4: pthread_setcancelstate
/* _background_signal_hand - Process daemon-wide signals for the
* backup controller */
static void *_background_signal_hand(void *no_data)
{
int sig, rc;
sigset_t set;
/* Locks: Write configuration, job, node, and partition */
slurmctld_lock_t config_write_lock = {
WRITE_LOCK, WRITE_LOCK, WRITE_LOCK, WRITE_LOCK };
(void) pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
(void) pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
while (slurmctld_config.shutdown_time == 0) {
xsignal_sigset_create(backup_sigarray, &set);
rc = sigwait(&set, &sig);
if (rc == EINTR)
continue;
switch (sig) {
case SIGINT: /* kill -2 or <CTRL-C> */
case SIGTERM: /* kill -15 */
info("Terminate signal (SIGINT or SIGTERM) received");
slurmctld_config.shutdown_time = time(NULL);
slurmctld_shutdown();
return NULL; /* Normal termination */
break;
case SIGHUP: /* kill -1 */
info("Reconfigure signal (SIGHUP) received");
/*
* XXX - need to shut down the scheduler
* plugin, re-read the configuration, and then
* restart the (possibly new) plugin.
*/
lock_slurmctld(config_write_lock);
_backup_reconfig();
/* Leave config lock set through this */
_update_cred_key();
unlock_slurmctld(config_write_lock);
break;
case SIGABRT: /* abort */
info("SIGABRT received");
slurmctld_config.shutdown_time = time(NULL);
slurmctld_shutdown();
dump_core = true;
return NULL; /* Normal termination */
break;
default:
error("Invalid signal (%d) received", sig);
}
}
return NULL;
}
示例5: sigemptyset
void *threadfunc2(void *pvoid)
{
int signum;
sigset_t sig;
sigemptyset(&sig);
sigaddset(&sig,SIGUSR1);
pthread_sigmask(SIG_BLOCK,&sig,NULL);//设置该线程的信号屏蔽字为SIGUSR1
while(1)
{
sigwait(&sig,&signum);//睡眠等待SIGUSR1信号的到来
printf("threadfunc2 waiting is over!\n");
}
}
示例6: jackctl_wait_signals
void
jackctl_wait_signals(sigset_t signals)
{
int sig;
bool waiting = true;
while (waiting) {
#if defined(sun) && !defined(__sun__) // SUN compiler only, to check
sigwait(&signals);
#else
sigwait(&signals, &sig);
#endif
fprintf(stderr, "jack main caught signal %d\n", sig);
switch (sig) {
case SIGUSR1:
//jack_dump_configuration(engine, 1);
break;
case SIGUSR2:
// driver exit
waiting = false;
break;
case SIGTTOU:
break;
default:
waiting = false;
break;
}
}
if (sig != SIGSEGV) {
// unblock signals so we can see them during shutdown.
// this will help prod developers not to lose sight of
// bugs that cause segfaults etc. during shutdown.
sigprocmask(SIG_UNBLOCK, &signals, 0);
}
}
示例7: pthread_kill
~Suppressor()
{
// We want to preserve errno when the Suppressor drops out of
// scope. Otherwise, one needs to potentially store errno when
// using the suppress() macro.
int _errno = errno;
// If the signal has become pending after we blocked it, we
// need to clear it before unblocking it.
if (!pending && signals::pending(signal)) {
// It is possible that in between having observed the pending
// signal with sigpending() and clearing it with sigwait(),
// the signal was delivered to another thread before we were
// able to clear it here. This can happen if the signal was
// generated for the whole process (e.g. a kill was issued).
// See 2.4.1 here:
// http://pubs.opengroup.org/onlinepubs/009695399/functions/xsh_chap02_04.html
// To handle the above scenario, one can either:
// 1. Use sigtimedwait() with a timeout of 0, to ensure we
// don't block forever. However, this only works on Linux
// and we may still swallow the signal intended for the
// process.
// 2. After seeing the pending signal, signal ourselves with
// pthread_kill prior to calling sigwait(). This can still
// swallow the signal intended for the process.
// We chose to use the latter technique as it works on all
// POSIX systems and is less likely to swallow process signals,
// provided the thread signal and process signal are not merged.
pthread_kill(pthread_self(), signal);
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, signal);
int result;
do {
int _ignored;
result = sigwait(&mask, &_ignored);
} while (result == -1 && errno == EINTR);
}
// Unblock the signal (only if we were the ones to block it).
if (unblock) {
signals::unblock(signal);
}
// Restore errno.
errno = _errno;
}
示例8: signal_thread
static void* signal_thread(void* arg)
{
pthread_attr_t tattr; /* Used to set thread to detached mode */
int err; /* Indicates an error from sigwait */
int signo; /* The signal number that has been caught */
pthread_t tid; /* ID of the thread that has been spawnned */
// Make sure any threads that are spawned are detached, so the OS
// can reclaim the resources in a timely fashion
pthread_attr_init(&tattr);
pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
for (;; ) {
// Check directory for updates
alarm(gperiod);
// Block until signal has been caught
err = sigwait(&mask, &signo);
if (err != 0) {
syslog(LOG_ERR, "sigwait failed");
exit(1);
}
switch (signo) {
case SIGHUP:
// Finish transfers, remove all clients
syslog(LOG_INFO, "Received SIGHUP");
kill_clients(remove_client_pipes[1], "Server received SIGHUP; Disconnect all clients.");
break;
case SIGALRM:
// See if directory has updated
syslog(LOG_INFO, "Received SIGALRM");
pthread_create(&tid, &tattr, send_updates, NULL);
break;
case SIGINT:
// Mainly used when not running in daemon mode
syslog(LOG_INFO, "Received SIGINT");
kill_clients(remove_client_pipes[1], "Server received SIGINT; Disconnect all clients.");
exit(0);
case SIGTERM:
syslog(LOG_INFO, "Received SIGTERM");
kill_clients(remove_client_pipes[1], "Server received SIGTERM; Disconnect all clients.");
exit(0);
default:
syslog(LOG_ERR, "Unexpected signal: %d", signo);
break;
}
}
}
示例9: sigemptyset
void *timekeeper_sigwait(void *arg) {
sigset_t sigset;
int sig;
sigemptyset(&sigset);
sigaddset(&sigset, SIGALRM);
while (true) {
// When SIGCONT is received after SIGSTOP, sigwait returns
// with EINTR ??
if (sigwait(&sigset, &sig) == EINTR) continue;
evq_timekeeper->interrupt();
}
return NULL;
}
示例10: io_signal_handler
static void io_signal_handler(int sig) {
sigset_t sigs_to_catch;
int caught;
sigemptyset(&sigs_to_catch);
sigaddset(&sigs_to_catch, SIGIO);
for (;;) {
sigwait(&sigs_to_catch, &caught);
if (SIGKILL == caught) {
return;
}
pthread_mutex_lock(&io_mutex);
pthread_cond_broadcast(&io_wait);
pthread_mutex_unlock(&io_mutex);
}
}
示例11: TEST
TEST(signal, sigwait) {
ScopedSignalHandler ssh(SIGALRM, HandleSIGALRM);
sigset_t wait_set;
sigemptyset(&wait_set);
sigaddset(&wait_set, SIGALRM);
alarm(1);
int received_signal;
errno = 0;
ASSERT_EQ(0, sigwait(&wait_set, &received_signal));
ASSERT_EQ(0, errno);
ASSERT_EQ(SIGALRM, received_signal);
}
示例12: xPortStartScheduler
/*
* See header file for description.
*/
portBASE_TYPE xPortStartScheduler( void )
{
portBASE_TYPE xResult;
int iSignal;
sigset_t xSignals;
sigset_t xSignalToBlock;
sigset_t xSignalsBlocked;
portLONG lIndex;
/* Establish the signals to block before they are needed. */
sigfillset( &xSignalToBlock );
/* Block until the end */
(void)pthread_sigmask( SIG_SETMASK, &xSignalToBlock, &xSignalsBlocked );
for ( lIndex = 0; lIndex < MAX_NUMBER_OF_TASKS; lIndex++ )
{
pxThreads[ lIndex ].uxCriticalNesting = 0;
}
/* Start the timer that generates the tick ISR. Interrupts are disabled
here already. */
prvSetupTimerInterrupt();
/* Start the first task. Will not return unless all threads are killed. */
vPortStartFirstTask();
/* This is the end signal we are looking for. */
sigemptyset( &xSignals );
sigaddset( &xSignals, SIG_RESUME );
while ( pdTRUE != xSchedulerEnd )
{
if ( 0 != sigwait( &xSignals, &iSignal ) )
{
printf( "Main thread spurious signal: %d\n", iSignal );
}
}
printf( "Cleaning Up, Exiting.\n" );
/* Cleanup the mutexes */
xResult = pthread_mutex_destroy( &xSuspendResumeThreadMutex );
xResult = pthread_mutex_destroy( &xSingleThreadMutex );
vPortFree( (void *)pxThreads );
/* Should not get here! */
return 0;
}
示例13: main
int main()
{
sigset_t newmask, pendingset;
int sig;
/* Empty set of blocked signals */
if (sigemptyset(&newmask) == -1 || sigemptyset(&pendingset) == -1) {
printf("Error in sigemptyset()\n");
return PTS_UNRESOLVED;
}
/* Add SIGUSR2 to the set of blocked signals */
if (sigaddset(&newmask, SIGUSR2) == -1) {
perror("Error in sigaddset()\n");
return PTS_UNRESOLVED;
}
/* Block SIGUSR2 */
if (sigprocmask(SIG_SETMASK, &newmask, NULL) == -1) {
printf("Error in sigprocmask()\n");
return PTS_UNRESOLVED;
}
/* Send SIGUSR2 signal to this process. Since it is blocked,
* it should be pending */
if (raise(SIGUSR2) != 0) {
printf("Could not raise SIGUSR2\n");
return PTS_UNRESOLVED;
}
/* Call sigwait and test if it passed/failed */
if (sigwait(&newmask, &sig) != 0) {
printf("Error in sigwait()\n");
printf("Test FAILED\n");
return PTS_FAIL;
}
/* If we get here, then the process was suspended until
* SIGUSR2 was raised. */
if (sig == SIGUSR2) {
printf("Test PASSED\n");
return PTS_PASS;
} else {
printf("Test FAILED\n");
return PTS_FAIL;
}
}
示例14: serve
void serve (const char* address, const char* port, std::size_t num_threads, webserver::request_handler& handler) {
#if defined(_WIN32)
// Initialise server.
w3c_sw::webserver::server s(address, port, num_threads, handler);
server = &s;
// Set console control handler to allow server to be stopped.
console_ctrl_function = boost::bind(&w3c_sw::webserver::server::stop, &s);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
// Run the server until stopped.
s.run();
#else // !defined(_WIN32)
// Block all signals for background thread.
sigset_t new_mask;
sigfillset(&new_mask);
sigset_t old_mask;
pthread_sigmask(SIG_BLOCK, &new_mask, &old_mask);
// Run server in background thread.
w3c_sw::webserver::server s(address, port, num_threads, handler);
server = &s;
boost::thread t(boost::bind(&w3c_sw::webserver::server::run, &s));
// Restore previous signals.
pthread_sigmask(SIG_SETMASK, &old_mask, 0);
// Wait for signal indicating time to shut down.
sigset_t wait_mask;
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
int sig = 0;
sigwait(&wait_mask, &sig);
// Stop the server.
s.stop();
t.join();
#endif // !defined(_WIN32)
server = NULL;
}
示例15: sleep
int WServer::waitForShutdown(const char *restartWatchFile)
{
#if !defined(WIN32)
if (!CatchSignals) {
for(;;)
sleep(0x1<<16);
}
#endif // WIN32
#ifdef WT_THREADED
#if !defined(_WIN32)
sigset_t wait_mask;
sigemptyset(&wait_mask);
sigaddset(&wait_mask, SIGHUP);
sigaddset(&wait_mask, SIGINT);
sigaddset(&wait_mask, SIGQUIT);
sigaddset(&wait_mask, SIGTERM);
pthread_sigmask(SIG_BLOCK, &wait_mask, 0);
for (;;) {
int sig;
sigwait(&wait_mask, &sig);
if (sig != -1) {
if (sig == SIGHUP) {
if (instance())
instance()->configuration().rereadConfiguration();
} else
return sig;
}
}
#else // WIN32
boost::mutex::scoped_lock terminationLock(terminationMutex);
SetConsoleCtrlHandler(console_ctrl_handler, TRUE);
while (!terminationRequested)
terminationCondition.wait(terminationLock);
SetConsoleCtrlHandler(console_ctrl_handler, FALSE);
return 0;
#endif // WIN32
#else
return 0;
#endif // WT_THREADED
}