本文整理汇总了C++中sigwait函数的典型用法代码示例。如果您正苦于以下问题:C++ sigwait函数的具体用法?C++ sigwait怎么用?C++ sigwait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigwait函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:CSU-GH,项目名称:okl4_3.0,代码行数:50,代码来源:shmt06.c
示例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;
}
开发者ID:SlaykovskiyHDNANO,项目名称:DieVolheid,代码行数:50,代码来源:posix_main.cpp
示例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;
}
开发者ID:analogdevicesinc,项目名称:libiio,代码行数:14,代码来源:iio_readdev.c
示例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;
}
开发者ID:surban,项目名称:slurm,代码行数:52,代码来源:backup.c
示例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");
}
}
开发者ID:yaxinsn,项目名称:makefile-and-gcc,代码行数:14,代码来源:sigwait.c
示例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);
}
}
开发者ID:Llefjord,项目名称:jack1,代码行数:37,代码来源:controlapi.c
示例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;
}
开发者ID:Adyoulike,项目名称:mesos,代码行数:49,代码来源:signals.hpp
示例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;
}
}
}
开发者ID:cmoresid,项目名称:dirapp,代码行数:49,代码来源:server.c
示例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;
}
开发者ID:LubosD,项目名称:twinkle,代码行数:15,代码来源:timekeeper.cpp
示例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);
}
}
开发者ID:GeyerA,项目名称:platform_frameworks_native,代码行数:15,代码来源:installd.c
示例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);
}
开发者ID:RUIXUEZHAOFENGNIAN,项目名称:platform_bionic,代码行数:15,代码来源:signal_test.cpp
示例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;
}
开发者ID:ICRS,项目名称:OpenPilot-Clone,代码行数:51,代码来源:port.c
示例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;
}
}
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:48,代码来源:8-1.c
示例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;
}
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:48,代码来源:WEBserver_asio.hpp
示例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
}
开发者ID:bvanhauwaert,项目名称:wt,代码行数:48,代码来源:WServer.C
示例16: main
int
main (int argc, char *argv[]) {
char *ifname, *hwaddr = NULL, *ipaddr;
sigset_t sigset;
int signo;
struct netdev *dev;
struct netif_ip iface = {};
switch (argc) {
case 4:
hwaddr = argv[2];
/* fall through */
case 3:
ipaddr = argv[argc-1];
ifname = argv[1];
break;
default:
fprintf(stderr, "usage: %s interface [mac_address] ip_address\n", argv[0]);
return -1;
}
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
sigprocmask(SIG_BLOCK, &sigset, NULL);
setup();
dev = netdev_alloc(NETDEV_TYPE_ETHERNET);
if (!dev) {
return -1;
}
strncpy(dev->name, ifname, sizeof(dev->name) -1);
if (hwaddr) {
ethernet_addr_pton(hwaddr, (ethernet_addr_t *)dev->addr);
}
if (dev->ops->open(dev, RAWDEV_TYPE_AUTO) == -1) {
return -1;
}
iface.netif.family = NETIF_FAMILY_IPV4;
ip_addr_pton(ipaddr, &iface.unicast);
netdev_add_netif(dev, (struct netif *)&iface);
dev->ops->run(dev);
while (1) {
sigwait(&sigset, &signo);
if (signo == SIGINT) {
break;
}
}
dev->ops->close(dev);
return 0;
}
开发者ID:pandax381,项目名称:microps,代码行数:48,代码来源:arp_test.c
示例17: while
void Process::Manager::SigchldThread(sigset_t * set, Process::Manager * master)
{
//Debug("Sigchld thread starts");
//pid_t this_tid = syscall(SYS_gettid);
while (master->m_running)
{
int sig = 0;
if (sigwait(set, &sig) != 0)
{
Error("Got error in sigwait - %s", StrError(errno));
break;
}
assert(sig == SIGCHLD);
//if (sig == SIGCHLD)
// Debug("Got SIGCHLD %d", sig);
//if (sig != SIGCHLD)
// Debug("Got signal %d", sig);
master->m_pid_mutex.lock();
while (true)
{
int status = 0;
pid_t pid = waitpid(-1, &status, WNOHANG);
//Debug("SIGCHLD - PID of child was %d", pid);
if (pid <= 0) break;
map<pid_t, Process*>::iterator it = master->m_pid_map.find(pid);
if (it == master->m_pid_map.end()) continue;
//it->second->Close();
it->second->m_status = status;
syscall(SYS_tgkill, getpid(), it->second->m_tid, SIGUSR1);
master->m_pid_map.erase(it);
}
// we need to interrupt any system calls involved with the child process
/*vector<int> tids;
Process::Manager::GetThreads(tids);
for (unsigned i = 0; i < tids.size(); ++i)
{
if (tids[i] == this_tid) continue;
syscall(SYS_tgkill, getpid(), tids[i], SIGUSR1);
}
*/
master->m_pid_mutex.unlock();
}
//Debug("Sigchld thread exits here");
}
开发者ID:szmoore,项目名称:foxbox,代码行数:48,代码来源:process.cpp
示例18: runTillStopped
void runTillStopped(){
// 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);
/*std::ofstream logFile;
logFile.open("log");
logFile << "STOP SIGNAL received";
logFile.close();*/
}
开发者ID:cmusatyalab,项目名称:GigaSight,代码行数:16,代码来源:Main.cpp
示例19: waitForSignals
void waitForSignals(sigset_t *signal_set, int& sig_number)
{
while (true) {
errno = 0;
int ret = sigwait(signal_set, &sig_number);
LOG_DEBUG("sigwait return value: %d \n", ret);
if (ret == 0) {
LOG_DEBUG("signal caught: %d\n", sig_number);
break;
} else {
char errstr[256];
strerror_r(errno, errstr, sizeof(errstr));
LOG_ERROR("error (%d) %s\n", errno, errstr);
}
}
}
开发者ID:longdafeng,项目名称:longda,代码行数:16,代码来源:lsignal.cpp
示例20: sigemptyset
//wait
void Signals::Wait(int signal)
{
#ifndef _WINDOWS
sigset_t signalSet;
sigemptyset(&signalSet);
sigaddset(&signalSet, signal);
LOG_DEBUG_APP("[Signal] waiting for signal=" << signal << "...");
int receivedSignal = 0;
sigwait(&signalSet, &receivedSignal);
LOG_INFO_APP("[Signal] received signal=" << receivedSignal);
#endif
}
开发者ID:irares,项目名称:WirelessHart-Gateway,代码行数:17,代码来源:Signals.cpp
注:本文中的sigwait函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论