本文整理汇总了C++中WCOREDUMP函数的典型用法代码示例。如果您正苦于以下问题:C++ WCOREDUMP函数的具体用法?C++ WCOREDUMP怎么用?C++ WCOREDUMP使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WCOREDUMP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: perror
bool process::kill(){
int r = ::kill(pid_, SIGTERM);
if(r!=0){
perror("cannot kill");
return false;
}
int status = 0;
waitpid(pid_, &status,0);
if(WCOREDUMP(status)){
LOG(ERROR) << name_ << " coredumped.";
}//TODO: add more error processing
DLOG(INFO) << "stopped: " << pid_;
DLOG(ERROR) << "stopped: " << pid_;
return true;
}
示例2: log_status
static void log_status (int status)
{
if (WIFEXITED (status)) {
if (0 == WEXITSTATUS (status))
syslog (LOG_INFO, "Info: collectd terminated with exit status %i",
WEXITSTATUS (status));
else
syslog (LOG_WARNING,
"Warning: collectd terminated with exit status %i",
WEXITSTATUS (status));
}
else if (WIFSIGNALED (status)) {
syslog (LOG_WARNING, "Warning: collectd was terminated by signal %i%s",
WTERMSIG (status), WCOREDUMP (status) ? " (core dumped)" : "");
}
return;
} /* log_status */
示例3: child_exited
static void child_exited(int sig)
{
struct rusage ru;
int status, result;
result = wait3(&status, 0, &ru);
printf("wait3() status: %d; return %d: %s\n",
status, result, strerror(errno));
if (WIFEXITED(status)) {
printf("Child with pid %d exited normally\n", result);
}
if (WIFSIGNALED(status)) {
printf("Child caught signal %d\n", WTERMSIG(status));
printf("Child did%s produce a core dump\n", WCOREDUMP(status) ? "" : " not");
}
exit(1);
}
示例4: prexit
void prexit(stat)
{
if (WIFEXITED(stat))
printf("normal termination, exit status = %d\n", WEXITSTATUS(stat));
else if (WIFSIGNALED(stat))
printf("abnormal termination, signal = %d %s\n", WTERMSIG(stat),
#ifdef WCOREDUMP
WCOREDUMP(stat) ? "( core file generated )" : ""
#else
""
#endif
);
else if (WIFSTOPPED(stat))
printf("child stopped, signal = %d\n", WSTOPSIG(stat));
else if (WIFCONTINUED(stat))
printf("child stopped, signal = %d\n", WSTOPSIG(stat));
}
示例5: _wait
static Waitmsg*
_wait(int pid4, int opt)
{
int pid, status, cd;
struct rusage ru;
char tmp[64];
ulong u, s;
Waitmsg *w;
w = malloc(sizeof *w + 200);
if(w == nil)
return nil;
memset(w, 0, sizeof *w);
w->msg = (char*)&w[1];
for(;;){
/* On Linux, pid==-1 means anyone; on SunOS, it's pid==0. */
if(pid4 == -1)
pid = wait3(&status, opt, &ru);
else
pid = wait4(pid4, &status, opt, &ru);
if(pid <= 0) {
free(w);
return nil;
}
u = ru.ru_utime.tv_sec*1000+((ru.ru_utime.tv_usec+500)/1000);
s = ru.ru_stime.tv_sec*1000+((ru.ru_stime.tv_usec+500)/1000);
w->pid = pid;
w->time[0] = u;
w->time[1] = s;
w->time[2] = u+s;
if(WIFEXITED(status)){
if(status)
sprint(w->msg, "%d", status);
return w;
}
if(WIFSIGNALED(status)){
cd = WCOREDUMP(status);
sprint(w->msg, "signal: %s", _p9sigstr(WTERMSIG(status), tmp));
if(cd)
strcat(w->msg, " (core dumped)");
return w;
}
}
}
示例6: log_coredump
static void
log_coredump(struct service *service, string_t *str, int status)
{
#ifdef WCOREDUMP
int signum = WTERMSIG(status);
if (WCOREDUMP(status)) {
str_append(str, " (core dumped)");
return;
}
if (signum != SIGABRT && signum != SIGSEGV && signum != SIGBUS)
return;
/* let's try to figure out why we didn't get a core dump */
if (core_dumps_disabled) {
str_printfa(str, " (core dumps disabled)");
return;
}
#ifndef HAVE_PR_SET_DUMPABLE
if (!service->set->drop_priv_before_exec && service->uid != 0) {
str_printfa(str, " (core not dumped - set service %s "
"{ drop_priv_before_exec=yes })",
service->set->name);
return;
}
if (*service->set->privileged_group != '\0' && service->uid != 0) {
str_printfa(str, " (core not dumped - service %s "
"{ privileged_group } prevented it)",
service->set->name);
return;
}
#else
if (!service->set->login_dump_core &&
service->type == SERVICE_TYPE_LOGIN) {
str_printfa(str, " (core not dumped - add -D parameter to "
"service %s { executable }", service->set->name);
return;
}
#endif
str_append(str, " (core not dumped)");
#endif
}
示例7: pr_exit
void
pr_exit(int status)
{
if (WIFEXITED(status)) {
printf("normal termination, exit status = %d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
printf("abnormal termination, signal number = %d%s\n",
WTERMSIG(status),
#ifdef WCOREDUMP
WCOREDUMP(status) ? " (core file generated)" : ""
#else
""
#endif
);
} else if (WIFSTOPPED(status)) {
printf("child stopped, signal number = %d\n", WSTOPSIG(status));
}
}
示例8: convert_broken
/// Writes a generic result file for an ATF broken result.
///
/// \param reason Textual explanation of the result.
/// \param status Exit code of the test program as returned by wait().
/// \param output Path to the generic result file to create.
/// \param [out] success Whether the result should be considered a success or
/// not; e.g. passed and skipped are successful, but failed is not.
///
/// \return An error if the conversion fails; OK otherwise.
static kyua_error_t
convert_broken(const char* reason, int status, const char* output,
bool* success)
{
if (WIFEXITED(status)) {
*success = false;
return kyua_result_write(
output, KYUA_RESULT_BROKEN, "%s; test case exited with code %d",
reason, WEXITSTATUS(status));
} else {
assert(WIFSIGNALED(status));
*success = false;
return kyua_result_write(
output, KYUA_RESULT_BROKEN, "%s; test case received signal %d%s",
reason, WTERMSIG(status),
WCOREDUMP(status) ? " (core dumped)" : "");
}
}
示例9: strbuf_append_exit_status
strbuf strbuf_append_exit_status(strbuf sb, int status)
{
if (WIFEXITED(status))
strbuf_sprintf(sb, "exited normally with status %u", WEXITSTATUS(status));
else if (WIFSIGNALED(status)) {
strbuf_sprintf(sb, "terminated by signal %u (%s)", WTERMSIG(status), strsignal(WTERMSIG(status)));
#ifdef WCOREDUMP
if (WCOREDUMP(status))
strbuf_puts(sb, " and dumped core");
#endif
} else if (WIFSTOPPED(status))
strbuf_sprintf(sb, "stopped by signal %u (%s)", WSTOPSIG(status), strsignal(WSTOPSIG(status)));
#ifdef WIFCONTINUED
else if (WIFCONTINUED(status))
strbuf_sprintf(sb, "continued by signal %u (SIGCONT)", SIGCONT);
#endif
return sb;
}
示例10: print_wait_status
static void
print_wait_status (int status)
{
if (WIFEXITED (status))
printf ("child exited, status:%d\n", WEXITSTATUS (status));
else if (WIFSIGNALED (status)) {
printf ("child killed by signal %s", strsignal (WTERMSIG (status)));
if (WCOREDUMP (status))
printf (" (core dumped)");
printf ("\n");
}
else if (WIFSTOPPED (status))
printf ("child stopped by signal %s\n", strsignal (WSTOPSIG (status)));
else if (WIFCONTINUED (status))
printf ("child continued\n");
else
printf ("what happened to this child? (status:0x%08x)\n", (unsigned)status);
}
示例11: subproc_check
static int
subproc_check(int status, const char *desc, enum subproc_flags flags)
{
void (*out)(const char *fmt, ...) DPKG_ATTR_PRINTF(1);
int n;
if (flags & SUBPROC_WARN)
out = warning;
else
out = ohshit;
if (WIFEXITED(status)) {
n = WEXITSTATUS(status);
if (!n)
return 0;
if (flags & SUBPROC_RETERROR)
return n;
out(_("subprocess %s returned error exit status %d"), desc, n);
} else if (WIFSIGNALED(status)) {
n = WTERMSIG(status);
if (!n)
return 0;
if ((flags & SUBPROC_NOPIPE) && n == SIGPIPE)
return 0;
if (flags & SUBPROC_RETSIGNO)
return n;
if (n == SIGINT)
out(_("subprocess %s was interrupted"), desc);
else
out(_("subprocess %s was killed by signal (%s)%s"),
desc, strsignal(n),
WCOREDUMP(status) ? _(", core dumped") : "");
} else {
if (flags & SUBPROC_RETERROR)
return -1;
out(_("subprocess %s failed with wait status code %d"), desc,
status);
}
return -1;
}
示例12: get_child_status
//
// Various signal/error handling functions that can't be put into the class
//
void get_child_status(const int waitpid_status, int &process_status, bool &exited, bool do_logging)
{
exited = false;
process_status = -1;
// The child process exited. Call its callback, and then clean it up
if (WIFEXITED(waitpid_status))
{
process_status = WEXITSTATUS(waitpid_status);
exited = true;
if (do_logging)
{
llinfos << "get_child_status - Child exited cleanly with return of " << process_status << llendl;
}
return;
}
else if (WIFSIGNALED(waitpid_status))
{
process_status = WTERMSIG(waitpid_status);
exited = true;
if (do_logging)
{
llinfos << "get_child_status - Child died because of uncaught signal " << process_status << llendl;
#ifdef WCOREDUMP
if (WCOREDUMP(waitpid_status))
{
llinfos << "get_child_status - Child dumped core" << llendl;
}
else
{
llinfos << "get_child_status - Child didn't dump core" << llendl;
}
#endif
}
return;
}
else if (do_logging)
{
// This is weird. I just dump the waitpid status into the status code,
// not that there's any way of telling what it is...
llinfos << "get_child_status - Got SIGCHILD but child didn't exit" << llendl;
process_status = waitpid_status;
}
}
示例13: child_waitpid
static gboolean
child_waitpid(mainloop_child_t *child, int flags)
{
int rc = 0;
int core = 0;
int signo = 0;
int status = 0;
int exitcode = 0;
rc = waitpid(child->pid, &status, flags);
if(rc == 0) {
crm_perror(LOG_DEBUG, "wait(%d) = %d", child->pid, rc);
return FALSE;
} else if(rc != child->pid) {
signo = SIGCHLD;
exitcode = 1;
status = 1;
crm_perror(LOG_ERR, "Call to waitpid(%d) failed", child->pid);
} else {
crm_trace("Managed process %d exited: %p", child->pid, child);
if (WIFEXITED(status)) {
exitcode = WEXITSTATUS(status);
crm_trace("Managed process %d (%s) exited with rc=%d", child->pid, child->desc, exitcode);
} else if (WIFSIGNALED(status)) {
signo = WTERMSIG(status);
crm_trace("Managed process %d (%s) exited with signal=%d", child->pid, child->desc, signo);
}
#ifdef WCOREDUMP
if (WCOREDUMP(status)) {
core = 1;
crm_err("Managed process %d (%s) dumped core", child->pid, child->desc);
}
#endif
}
if (child->callback) {
child->callback(child, child->pid, core, signo, exitcode);
}
return TRUE;
}
示例14: affichage_type_de_terminaison
void affichage_type_de_terminaison (pid_t pid, int status)
{
fprintf(stdout, "Le processus %ld ", (long)pid);
if (WIFEXITED(status)) {
fprintf (stdout, "s'est termine normalement avec le code %d\n",
WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
fprintf (stdout, "s'est termine a cause du signal %d (%s)\n",
WTERMSIG(status),
sys_siglist[WTERMSIG(status)]);
if (WCOREDUMP(status)) {
fprintf(stdout, "Fichier image core cree\n");
}
} else if (WIFSTOPPED(status)) {
fprintf(stdout, "s'est arrete a cause du signal %d (%s)\n",
WSTOPSIG(status),
sys_siglist[WSTOPSIG(status)]);
}
}
示例15: main
int main(int argc, char *argv[]) {
pid_t pid;
int status, retval, whatToDo = 0;
char str[8];
if (argc > 1)
whatToDo = atoi(argv[1]); // get job number for child
pid = fork(); // fork child
switch (pid) {
case -1:
perror("Could not fork");
break;
case 0:
sprintf(str, "%d",whatToDo);
retval = execl("./ChildProgA8.e", "ChildProgA8.e", str, NULL);
if (retval < 0) perror("\nexecl not successful");
break;
default:
if (whatToDo <= 3) {
if (whatToDo == 3) {
sleep(1);
kill(pid, SIGABRT); // send signal SIGABTR to child
}
wait(&status);
if (WIFEXITED(status))
printf("Child exits with status %d\n", WEXITSTATUS(status));
if (WIFSIGNALED(status)) {
printf("Child exits on signal %d\n", WTERMSIG(status));
printf("Child exits with core dump %d\n", WCOREDUMP(status));
}
} else {
usleep(500*1000);
while (!waitpid(pid, &status, WNOHANG)) {
printf(". . . child is playing\n");
usleep(500*1000);
}
printf("Child has exited with 'exit(%d)'\n", WEXITSTATUS(status));
}
break;
}
exit(0);
}