本文整理汇总了C++中sigset函数的典型用法代码示例。如果您正苦于以下问题:C++ sigset函数的具体用法?C++ sigset怎么用?C++ sigset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char * argv[])
{
/*Set up some Variables*/
int parent_PCB_id = argc;
int fid;
caddr_t mmap_ptr;
inputbuf *in_mem_p;
char c[MAX_CHAR];
// If parent tells us to terminate, then clean up first
sigset(SIGINT,in_die);
//Gets id of parents (to signal) and the file id of mmap.
sscanf(argv[1], "%d", &parent_PCB_id);
sscanf(argv[2], "%d", &kfid );
kmmap_ptr =
mmap((caddr_t) 0,
bufsize,
PROT_READ | PROT_WRITE,
MAP_SHARED,
kfid,
(off_t) 0);
if (kmmap_ptr == MAP_FAILED){
printf("Child memory map has failed, KB is aborting! Error <%s> ...\n", strerror(errno));
in_die(0);
}
in_mem_p = (inputbuf *) kmmap_ptr;
buf_index = 0;
in_mem_p->flag = MEM_EMPTY; // Set the flag to “Buffer Empty”
do {
fgets(c, MAX_CHAR, stdin); // This only returns when <cr> is pressed
strcpy(in_mem_p->data, c); // Read in data from buffer
in_mem_p->flag = MEM_FULL; // Set the flag
kill(parent_PCB_id ,SIGUSR1); // Signal the parent
buf_index = 0;
while(in_mem_p->flag == MEM_FULL){
usleep(100000); // Sleep until the RTX has read the data
}
} while(1); // Loops Forever
}
示例2: main
int main()
{
struct sigaction act;
act.sa_flags = 0;
act.sa_handler = myhandler;
sigemptyset(&act.sa_mask);
if (sigaction(SIGUSR1, &act, 0) != 0) {
perror("Unexpected error while using sigaction()");
return PTS_UNRESOLVED;
}
if (sigset(SIGUSR1,SIG_DFL) != myhandler) {
printf("Test FAILED: sigset didn't return myhandler even though it was SIGUSR1's original disposition\n");
return PTS_FAIL;
}
return PTS_PASS;
}
示例3: _tt_sigset
/*
* _tt_sigset sets up a signal handler in such a way that the handler
* is *not* unregistered when the signal handler is entered. If
* returns 0 if an error occurs, else 1, and leaves errno set according
* to the underlying system call (sigaction, signal, sigset.)
*/
int
_tt_sigset(
int sig,
SIG_PF handler )
{
#if defined(OPT_POSIX_SIGNAL)
/*
* There seems to be some controversy over the type of sa_handler in
* C++ programs. Everybody\'s man page seems to say it is of type
* "void (*)()", and that\'s what Solaris does, and I think that\'s what
* POSIX says, but both HP and IBM define it as the arguably much more
* useful "void (*)(int)", a/k/a SIG_PF.
*
* [4 Apr 95] Solaris 2.5 has switched to use void (*)(int), which
* is nice for the long run but causes us some short-run problems
* as we want this level of the source to compile both on
* Solaris 2.4 and Solaris 2.5 for a while. To solve this, we use
* the "sa_sigaction" element of the sigaction structure, which is the
* three-argument flavor of the function pointer. This is, strictly,
* a lie, but it's safe since our signal handlers never look at the
* arguments anyway. sa_sigaction is, fortunately, the same on all
* Solaris versions.
* Once the requirement to compile on Solaris 2.4 goes away, we can
* simply remove the OPT_BUG_SUNOS_5 ifdefs here, leaving only the
* UnixWare one.
*/
struct sigaction act;
#if defined(OPT_BUG_SUNOS_5)
act.sa_sigaction = (void (*)(int, siginfo_t *, void *)) handler;
#elif defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
act.sa_handler = (void (*)()) handler;
#else
act.sa_handler = handler;
#endif
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
return 0==sigaction(sig, &act, NULL);
#elif defined(OPT_BSD_SIGNAL)
return SIG_ERR!=signal(sig, handler);
#else
return SIG_ERR!=sigset(sig, handler);
#endif
}
示例4: main
int
main(int argc, char * argv[])
{
if(argc!=2)
{
printf("usage: sleep <sleep in seconds>\n");
printf("used to test sleep() and sending a alarm signal -14 affects process\n");
printf("the signal will wakeup a process doing sleep and should return");
printf(" number of seconds left to sleep\n");
exit(0);
}
// set the alaram signal
//
sigset(SIGALRM, SIG_IGN);
unsigned int sleepTime = atoi(argv[1]);
unsigned int timeSlept;
time_t currTime = time(NULL);
struct tm currStruct;
localtime_r(&currTime, &currStruct);
printf("current time: %s\n", asctime(&currStruct));
timeSlept = sleepTime;
while ((timeSlept = sleep(timeSlept)) != 0)
{
// woke up early
//
printf("woke up early need to sleep: %u more\n", timeSlept);
currTime = time(NULL);
localtime_r(&currTime, &currStruct);
printf("current time: %s\n", asctime(&currStruct));
}
currTime = time(NULL);
localtime_r(&currTime, &currStruct);
printf("end time: %s\n", asctime(&currStruct));
return 0;
}
示例5: pipeback_shell_close
void pipeback_shell_close (FILE *file)
{
#ifndef NOCLDWAIT
int wait_status = 0;
#endif
int cresult = fclose (file);
if (cresult) fprintf (stderr, "Warning. Error closing pipeback file.\n");
if (0 == --Usage)
{
if (SIG_ERR == sigset (SIGCHLD, SIG_DFL))
{
fprintf (stderr,
"Warning. Error resetting SIGCHLD action after pipeback.\n");
}
#ifndef NOCLDWAIT
wait (&wait_status);
#endif
}
}
示例6: setup
static void setup(void)
{
char wdbuf[MAXPATHLEN];
/*
* Make a directory to do this in; ignore error if already exists.
* Save starting directory.
*/
tst_tmpdir();
if (getcwd(homedir, sizeof(homedir)) == NULL) {
tst_brkm(TBROK | TERRNO, NULL, "getcwd() failed");
}
parent_pid = getpid();
if (!fuss[0])
sprintf(fuss, "%s/ftest03.%d", getcwd(wdbuf, sizeof(wdbuf)),
getpid());
mkdir(fuss, 0755);
if (chdir(fuss) < 0) {
tst_resm(TBROK, "\tCan't chdir(%s), error %d.", fuss, errno);
tst_exit();
}
/*
* Default values for run conditions.
*/
iterations = 10;
nchild = 5;
csize = K_2; /* should run with 1, 2, and 4 K sizes */
max_size = K_1 * K_1;
misc_intvl = 10;
if (sigset(SIGTERM, term) == SIG_ERR) {
perror("sigset failed");
tst_resm(TBROK, " sigset failed: signo = 15");
tst_exit();
}
}
示例7: main
int main(void)
{
char buf[LINE_LEN];
pid_t pid;
int status;
if(sigset(SIGINT, sigint)== SIG_ERR)
perror("sigint");
printf("->:");
for(;;)
{
while(fgets(buf,LINE_LEN,stdin)!=NULL)
{
if(*buf != '\0')
buf[strlen(buf)-1]='\0';
printf("->:");
continue;
}
switch (pid = fork()){
case -1:
perror("fork failed");
break;
case 0:
execlp(buf,buf,NULL);
perror("cannot execlp");
break;
default :
if(waitpid(pid,&status,0)==-1)
perror("waitpid");
break;
}
printf("->:");
if(errno != EINTR)
break;
errno = 0;
}
return (0);
}
示例8: doinput
void
doinput()
{
char ibuf[BUFSIZ];
int cc;
(void) fclose(fscript);
sigset(SIGWINCH, sigwinch);
while ((cc = read(0, ibuf, BUFSIZ)) != 0) {
if (cc == -1) {
if (errno == EINTR) { /* SIGWINCH probably */
continue;
} else {
break;
}
}
(void) write(master, ibuf, cc);
}
done();
}
示例9: main
int main()
{
sigset_t mask;
sigemptyset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
if (sigset(SIGCHLD, myhandler) == SIG_ERR) {
perror("Unexpected error while using sigset()");
return PTS_UNRESOLVED;
}
raise(SIGCHLD);
sigprocmask(SIG_SETMASK, NULL, &mask);
if (is_empty(&mask) != 1) {
printf("Test FAILED: signal mask should be empty\n");
return PTS_FAIL;
}
return PTS_PASS;
}
示例10: returnTest2
static int
returnTest2 (void)
{
sighandler_t prev;
printf ("\n===== TEST 2 =====\n");
printf ("About to use sigset() to set SIG_HOLD\n");
prev = sigset (TEST_SIG, SIG_HOLD);
if (prev == SIG_ERR)
error (1, errno, "sigset");
printf ("Previous disposition: ");
printDisposition (prev);
printf (" (should be SIG_DFL)\n");
if (prev != SIG_DFL)
{
printf("TEST FAILED!!!\n");
return 1;
}
return 0;
} /* returnTest2 */
示例11: ktrsigaction
static void
ktrsigaction(const struct sigaction *sa)
{
/*
* note: ktrstruct() has already verified that sa points to a
* buffer exactly sizeof(struct sigaction) bytes long.
*/
printf("struct sigaction { ");
if (sa->sa_handler == SIG_DFL)
printf("handler=SIG_DFL");
else if (sa->sa_handler == SIG_IGN)
printf("handler=SIG_IGN");
else if (sa->sa_flags & SA_SIGINFO)
printf("sigaction=%p", (void *)sa->sa_sigaction);
else
printf("handler=%p", (void *)sa->sa_handler);
printf(", mask=");
sigset(sa->sa_mask);
printf(", flags=");
sigactionflagname(sa->sa_flags);
printf(" }\n");
}
示例12: BSP_Reset
void BSP_Reset(void)
{
pid_t pid = getpid();
char cmdline_file[200];
char cmdline[1024];
int cfd, r;
snprintf(cmdline_file, 200, CMDLINE_FILE, pid);
cfd = open(cmdline_file, O_RDONLY);
if (cfd < 0) {
printf("Reboot failed: Cannot access %s: %s\n", cmdline_file, strerror(errno));
exit(2);
}
r = read(cfd, cmdline, 1024);
if (r < 0) {
printf("Reboot failed: Cannot read cmdline from proc file\n");
exit(2);
}
printf("############ Rebooting...\n\n\n");
sigset(SIGALRM, SIG_IGN);
execl(cmdline, cmdline, NULL);
}
示例13: init
static void init(void)
{
int fd;
char wdbuf[MAXPATHLEN];
parent_pid = getpid();
tst_tmpdir();
/*
* Make a filename for the test.
*/
if (!filename[0])
sprintf(filename, "%s/ftest08.%d", getcwd(wdbuf, MAXPATHLEN),
getpid());
fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
tst_resm(TBROK, "Error %d creating file %s", errno, filename);
tst_exit();
}
close(fd);
/*
* Default values for run conditions.
*/
iterations = 10;
nchild = 5;
csize = K_2; /* should run with 1, 2, and 4 K sizes */
max_size = K_1 * K_1;
misc_intvl = 10;
if (sigset(SIGTERM, term) == SIG_ERR) {
tst_brkm(TBROK | TERRNO, NULL, "first sigset failed");
}
}
示例14: main
int main(void)
{
sigset_t pendingset;
struct sigaction act;
act.sa_handler = myhandler;
act.sa_flags = 0;
sigemptyset(&act.sa_mask);
int rc;
rc = sigaction(SIGCHLD, &act, 0);
if (rc) {
ERR_MSG("sigaction()", rc);
return PTS_UNRESOLVED;
}
if (sigset(SIGCHLD, SIG_HOLD) == SIG_ERR) {
perror("Unexpected error while using sigset()");
return PTS_UNRESOLVED;
}
raise(SIGCHLD);
rc = sigpending(&pendingset);
if (rc) {
ERR_MSG("sigpending()", rc);
return PTS_UNRESOLVED;
}
if (sigismember(&pendingset, SIGCHLD) != 1) {
printf("Test FAILED: Signal SIGCHLD wasn't hold.\n");
return PTS_FAIL;
}
printf("Test PASSED\n");
return PTS_PASS;
}
示例15: main
int /* O - Exit status */
main(int argc, /* I - Number of command-line arguments (6 or 7) */
char *argv[]) /* I - Command-line arguments */
{
const char *device_uri; /* Device URI */
char scheme[255], /* Scheme in URI */
hostname[1024], /* Hostname */
username[255], /* Username info (not used) */
resource[1024], /* Resource info (not used) */
*options, /* Pointer to options */
*name, /* Name of option */
*value, /* Value of option */
sep; /* Option separator */
int print_fd; /* Print file */
int copies; /* Number of copies to print */
time_t start_time; /* Time of first connect */
#ifdef __APPLE__
time_t current_time, /* Current time */
wait_time; /* Time to wait before shutting down socket */
#endif /* __APPLE__ */
int contimeout; /* Connection timeout */
int waiteof; /* Wait for end-of-file? */
int port; /* Port number */
char portname[255]; /* Port name */
int delay; /* Delay for retries... */
int device_fd; /* AppSocket */
int error; /* Error code (if any) */
http_addrlist_t *addrlist, /* Address list */
*addr; /* Connected address */
char addrname[256]; /* Address name */
int snmp_fd, /* SNMP socket */
start_count, /* Page count via SNMP at start */
page_count, /* Page count via SNMP */
have_supplies; /* Printer supports supply levels? */
ssize_t bytes = 0, /* Initial bytes read */
tbytes; /* Total number of bytes written */
char buffer[1024]; /* Initial print buffer */
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; /* Actions for POSIX signals */
#endif /* HAVE_SIGACTION && !HAVE_SIGSET */
/*
* Make sure status messages are not buffered...
*/
setbuf(stderr, NULL);
/*
* Ignore SIGPIPE signals...
*/
#ifdef HAVE_SIGSET
sigset(SIGPIPE, SIG_IGN);
#elif defined(HAVE_SIGACTION)
memset(&action, 0, sizeof(action));
action.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &action, NULL);
#else
signal(SIGPIPE, SIG_IGN);
#endif /* HAVE_SIGSET */
/*
* Check command-line...
*/
if (argc == 1)
{
printf("network socket \"Unknown\" \"%s\"\n",
_cupsLangString(cupsLangDefault(), _("AppSocket/HP JetDirect")));
return (CUPS_BACKEND_OK);
}
else if (argc < 6 || argc > 7)
{
_cupsLangPrintf(stderr,
_("Usage: %s job-id user title copies options [file]"),
argv[0]);
return (CUPS_BACKEND_FAILED);
}
/*
* If we have 7 arguments, print the file named on the command-line.
* Otherwise, send stdin instead...
*/
if (argc == 6)
{
print_fd = 0;
copies = 1;
}
else
{
/*
* Try to open the print file...
*/
if ((print_fd = open(argv[6], O_RDONLY)) < 0)
{
_cupsLangPrintError("ERROR", _("Unable to open print file"));
return (CUPS_BACKEND_FAILED);
//.........这里部分代码省略.........