当前位置: 首页>>代码示例>>C++>>正文


C++ WIFSTOPPED函数代码示例

本文整理汇总了C++中WIFSTOPPED函数的典型用法代码示例。如果您正苦于以下问题:C++ WIFSTOPPED函数的具体用法?C++ WIFSTOPPED怎么用?C++ WIFSTOPPED使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了WIFSTOPPED函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execs

//Function for executing all the basic shell commands
void execs(char *arr[],int rlflag,int rgflag)
{
	int sin=dup(STDIN_FILENO);
	int sout=dup(STDOUT_FILENO);
	pp=fork();
	if(flag==0)
	{
		if(pp<0)
		{
			perror("Error");
			exit(0);
		}
		else if (pp==0)
		{
			if(rlflag==1)
			{
				FILE *fp=fopen(in1,"r");
				dup2(fileno(fp),0);
				fclose(fp);
			}
			if(rgflag==1)
			{
				FILE *fp=fopen(out1,"w+");
				dup2(fileno(fp),1);
				fclose(fp);
			}
			int val=execvp(arr[0],arr);
			if(val<0)
			{
				perror("Command not found");
				exit(0);
			}
		}
		else
		{	int s;
			waitpid(pp,&s,WUNTRACED);
			if(WIFSTOPPED(s))
			{
				strcpy(procs[counters].name,arr[0]);
				procs[counters].pid=pp;
				procs[counters++].status=1;
			}

		}

	}
	else if (flag==1)
	{
		if(pp<0)
		{
			perror("Error");
			exit(0);
		}
		else if (pp==0)
		{	if(rlflag==1)
			{
				FILE *fp=fopen(in1,"r");
				dup2(fileno(fp),0);
			}
			if(rgflag==1)
			{
				FILE *fp=fopen(out1,"w+");
				dup2(fileno(fp),1);
			}

			int val=execvp(arr[0],arr);
			if(val<0)
			{
				perror("Command Not Found");
				exit(0);
			}
		}
		else
		{
			strcpy(procs[counters].name,arr[0]);
			if((strcmp(arr[0],"gedit")==0||strcmp(arr[0],"emacs")==0)&&arr[1]!=NULL)
				strcpy(procs[counters].name2,arr[1]);
			procs[counters].pid=pp;
			procs[counters++].status=1;
		}
	}
	dup2(sout,1);
	dup2(sin,0);
	close(sout);
	close(sin);
}
开发者ID:ankitkotak93,项目名称:C-Terminal,代码行数:87,代码来源:201202102_Assignment3B.c

示例2: summarize

static void summarize (FILE *fp, const char *fmt, char **command, resource_t *resp)
{
    unsigned long r;		/* Elapsed real milliseconds.  */
    unsigned long v;		/* Elapsed virtual (CPU) milliseconds.  */

    if (WIFSTOPPED (resp->waitstatus))
	fprintf (fp, "Command stopped by signal %d\n", WSTOPSIG (resp->waitstatus));
    else if (WIFSIGNALED (resp->waitstatus))
	fprintf (fp, "Command terminated by signal %d\n", WTERMSIG (resp->waitstatus));
    else if (WIFEXITED (resp->waitstatus) && WEXITSTATUS (resp->waitstatus))
	fprintf (fp, "Command exited with non-zero status %d\n", WEXITSTATUS (resp->waitstatus));

    /* Convert all times to milliseconds.  Occasionally, one of these values
       comes out as zero.  Dividing by zero causes problems, so we first
       check the time value.  If it is zero, then we take `evasive action'
       instead of calculating a value.  */

    r = resp->elapsed.tv_sec * 1000 + resp->elapsed.tv_usec / 1000;

    v = resp->ru.ru_utime.tv_sec * 1000 + resp->ru.ru_utime.TV_MSEC +
	resp->ru.ru_stime.tv_sec * 1000 + resp->ru.ru_stime.TV_MSEC;

    while (*fmt)
    {
	switch (*fmt)
	{
	    case '%':
		switch (*++fmt)
		{
		    case '%':		/* Literal '%'.  */
			putc ('%', fp);
			break;
		    case 'C':		/* The command that got timed.  */
			fprintargv (fp, command, " ");
			break;
		    case 'D':		/* Average unshared data size.  */
			fprintf (fp, "%lu",
				MSEC_TO_TICKS (v) == 0 ? 0 :
				ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) +
				ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v));
			break;
		    case 'E':		/* Elapsed real (wall clock) time.  */
			if (resp->elapsed.tv_sec >= 3600)	/* One hour -> h:m:s.  */
			    fprintf (fp, "%ldh %ldm %02lds",
				    resp->elapsed.tv_sec / 3600,
				    (resp->elapsed.tv_sec % 3600) / 60,
				    resp->elapsed.tv_sec % 60);
			else
			    fprintf (fp, "%ldm %ld.%02lds",	/* -> m:s.  */
				    resp->elapsed.tv_sec / 60,
				    resp->elapsed.tv_sec % 60,
				    resp->elapsed.tv_usec / 10000);
			break;
		    case 'F':		/* Major page faults.  */
			fprintf (fp, "%ld", resp->ru.ru_majflt);
			break;
		    case 'I':		/* Inputs.  */
			fprintf (fp, "%ld", resp->ru.ru_inblock);
			break;
		    case 'K':		/* Average mem usage == data+stack+text.  */
			fprintf (fp, "%lu",
				MSEC_TO_TICKS (v) == 0 ? 0 :
				ptok ((UL) resp->ru.ru_idrss) / MSEC_TO_TICKS (v) +
				ptok ((UL) resp->ru.ru_isrss) / MSEC_TO_TICKS (v) +
				ptok ((UL) resp->ru.ru_ixrss) / MSEC_TO_TICKS (v));
			break;
		    case 'M':		/* Maximum resident set size.  */
			fprintf (fp, "%lu", ptok ((UL) resp->ru.ru_maxrss));
			break;
		    case 'O':		/* Outputs.  */
			fprintf (fp, "%ld", resp->ru.ru_oublock);
			break;
		    case 'P':		/* Percent of CPU this job got.  */
			/* % cpu is (total cpu time)/(elapsed time).  */
			if (r > 0)
			    fprintf (fp, "%lu%%", (v * 100 / r));
			else
			    fprintf (fp, "?%%");
			break;
		    case 'R':		/* Minor page faults (reclaims).  */
			fprintf (fp, "%ld", resp->ru.ru_minflt);
			break;
		    case 'S':		/* System time.  */
			fprintf (fp, "%ld.%02ld",
				resp->ru.ru_stime.tv_sec,
				resp->ru.ru_stime.TV_MSEC / 10);
			break;
		    case 'T':		/* System time.  */
			if (resp->ru.ru_stime.tv_sec >= 3600)	/* One hour -> h:m:s.  */
			    fprintf (fp, "%ldh %ldm %02lds",
				    resp->ru.ru_stime.tv_sec / 3600,
				    (resp->ru.ru_stime.tv_sec % 3600) / 60,
				    resp->ru.ru_stime.tv_sec % 60);
			else
			    fprintf (fp, "%ldm %ld.%02lds",	/* -> m:s.  */
				    resp->ru.ru_stime.tv_sec / 60,
				    resp->ru.ru_stime.tv_sec % 60,
				    resp->ru.ru_stime.tv_usec / 10000);
			break;
		    case 'U':		/* User time.  */
//.........这里部分代码省略.........
开发者ID:OpenHMR,项目名称:Open-HMR600,代码行数:101,代码来源:time.c

示例3: printYAMLJobInfo

int printYAMLJobInfo(FILE *out, int indent, const char* tag, const JobInfo* job) {
    /* purpose: format the job information into the given stream as YAML.
     * paramtr: out (IO): the stream
     *          indent (IN): indentation level
     *          tag (IN): name to use for element tags.
     *          job (IN): job info to print.
     * returns: number of characters put into buffer (buffer length)
     */

    /* sanity check */
    if (!job->isValid) {
        return 0;
    }

    /* start tag with indentation */
    fprintf(out, "%*s%s:\n", indent, "", tag);
    fprintf(out, "%*s  start: %s\n", indent, "", 
            fmtisodate(job->start.tv_sec, job->start.tv_usec));
    fprintf(out, "%*s  duration: %.3f\n", indent, "", 
            doubletime(job->finish) - doubletime(job->start));

    /* optional attribute: application process id */
    if (job->child != 0) {
        fprintf(out, "%*s  pid: %d\n", indent, "", job->child);
    }

    /* <usage> */
    printYAMLUseInfo(out, indent+2, "usage", &job->use);

    int status = (int) job->status;

    /* <status>: open tag */
    fprintf(out, "%*sstatus:\n%*sraw: %d\n",
                 indent+2, "", indent+4, "", status);

    /* <status>: cases of completion */
    if (status < 0) {
        /* <failure> */
        fprintf(out, "%*sfailure_error: %d   %s%s\n", indent+4, "",
                     job->saverr,
                     job->prefix && job->prefix[0] ? job->prefix : "",
                     strerror(job->saverr));
    } else if (WIFEXITED(status)) {
        fprintf(out, "%*sregular_exitcode: %d\n", indent+4, "",
                     WEXITSTATUS(status));
    } else if (WIFSIGNALED(status)) {
        /* result = 128 + WTERMSIG(status); */
        fprintf(out, "%*ssignalled_signal: %u\n", indent+4, "",
                     WTERMSIG(status));
        fprintf(out, "%*ssingalled_name: %s\n", indent+4, "",
                     sys_siglist[WTERMSIG(status)]);
#ifdef WCOREDUMP
        fprintf(out, "%*scorefile: %s\n", indent+4, "",
                     WCOREDUMP(status) ? "true" : "false");
#endif
    } else if (WIFSTOPPED(status)) {
        fprintf(out, "%*ssuspended_signal: %u\n", indent+4, "",
                     WSTOPSIG(status));
        fprintf(out, "%*ssuspended_name: %s\n", indent+4, "",
                sys_siglist[WSTOPSIG(status)]);
    } /* FIXME: else? */

    /* <executable> */
    printYAMLStatInfo(out, indent+2, "executable", &job->executable, 1, 0, 1);

    /* alternative 1: new-style <argument-vector> */
    fprintf(out, "%*sargument_vector:\n", indent+2, "");
    if (job->argc > 1) {
        /* content are the CLI args */
        int i;
        for (i=1; i<job->argc; ++i) {
            fprintf(out, "%*s- %s\n", indent+4, "", job->argv[i]);
        }
    }

    /* <proc>s */
    printYAMLProcInfo(out, indent+2, job->children);

    return 0;
}
开发者ID:pegasus-isi,项目名称:pegasus,代码行数:80,代码来源:jobinfo.c

示例4: handle_child

static void handle_child(pid_t childpid, int childstatus)
{
	unsigned int i;
	int slot;

	switch (childpid) {
	case 0:
		//debugf("Nothing changed. children:%d\n", shm->running_childs);
		break;

	case -1:
		if (shm->exit_reason != STILL_RUNNING)
			return;

		if (errno == ECHILD) {
			debugf("All children exited!\n");
			for_each_pidslot(i) {
				if (shm->pids[i] != EMPTY_PIDSLOT) {
					if (pid_alive(shm->pids[i]) == -1) {
						debugf("Removing %d from pidmap\n", shm->pids[i]);
						shm->pids[i] = EMPTY_PIDSLOT;
						shm->running_childs--;
					} else {
						debugf("%d looks still alive! ignoring.\n", shm->pids[i]);
					}
				}
			}
			break;
		}
		output(0, "error! (%s)\n", strerror(errno));
		break;

	default:
		debugf("Something happened to pid %d\n", childpid);

		if (WIFEXITED(childstatus)) {

			slot = find_pid_slot(childpid);
			if (slot == PIDSLOT_NOT_FOUND) {
				/* If we reaped it, it wouldn't show up, so check that. */
				if (shm->last_reaped != childpid) {
					outputerr("## Couldn't find pid slot for %d\n", childpid);
					shm->exit_reason = EXIT_LOST_PID_SLOT;
					dump_pid_slots();
				}
			} else {
				debugf("Child %d exited after %ld syscalls.\n", childpid, shm->child_syscall_count[slot]);
				reap_child(childpid);
			}
			break;

		} else if (WIFSIGNALED(childstatus)) {

			switch (WTERMSIG(childstatus)) {
			case SIGALRM:
				debugf("got a alarm signal from pid %d\n", childpid);
				break;
			case SIGFPE:
			case SIGSEGV:
			case SIGKILL:
			case SIGPIPE:
			case SIGABRT:
				debugf("got a signal from pid %d (%s)\n", childpid, strsignal(WTERMSIG(childstatus)));
				reap_child(childpid);
				break;
			default:
				debugf("** Child got an unhandled signal (%d)\n", WTERMSIG(childstatus));
				break;
			}
			break;

		} else if (WIFSTOPPED(childstatus)) {

			switch (WSTOPSIG(childstatus)) {
			case SIGALRM:
				debugf("got an alarm signal from pid %d\n", childpid);
				break;
			case SIGSTOP:
				debugf("Sending PTRACE_DETACH (and then KILL)\n");
				//ptrace(PTRACE_DETACH, childpid, NULL, NULL);
				kill(childpid, SIGKILL);
				reap_child(childpid);
				break;
			case SIGFPE:
			case SIGSEGV:
			case SIGKILL:
			case SIGPIPE:
			case SIGABRT:
				debugf("Child %d was stopped by %s\n", childpid, strsignal(WTERMSIG(childstatus)));
				reap_child(childpid);
				break;
			default:
				debugf("Child %d was stopped by unhandled signal (%s).\n", childpid, strsignal(WSTOPSIG(childstatus)));
				break;
			}
			break;

		} else if (WIFCONTINUED(childstatus)) {
			break;
		} else {
//.........这里部分代码省略.........
开发者ID:Berrrry,项目名称:trinity-osxnew,代码行数:101,代码来源:main.c

示例5: userspace

void userspace(union uml_pt_regs *regs)
{
	int err, status, op, pt_syscall_parm, pid = userspace_pid[0];
	int local_using_sysemu; /*To prevent races if using_sysemu changes under us.*/

	restore_registers(regs);
		
	local_using_sysemu = get_using_sysemu();

	pt_syscall_parm = local_using_sysemu ? PTRACE_SYSEMU : PTRACE_SYSCALL;
	err = ptrace(pt_syscall_parm, pid, 0, 0);

	if(err)
		panic("userspace - PTRACE_%s failed, errno = %d\n",
		       local_using_sysemu ? "SYSEMU" : "SYSCALL", errno);
	while(1){
		CATCH_EINTR(err = waitpid(pid, &status, WUNTRACED));
		if(err < 0)
			panic("userspace - waitpid failed, errno = %d\n", 
			      errno);

		regs->skas.is_user = 1;
		save_registers(regs);

		if(WIFSTOPPED(status)){
		  	switch(WSTOPSIG(status)){
			case SIGSEGV:
				handle_segv(pid);
				break;
			case SIGTRAP:
			        handle_trap(pid, regs, local_using_sysemu);
				break;
			case SIGIO:
			case SIGVTALRM:
			case SIGILL:
			case SIGBUS:
			case SIGFPE:
			case SIGWINCH:
				user_signal(WSTOPSIG(status), regs);
				break;
			default:
			        printk("userspace - child stopped with signal "
				       "%d\n", WSTOPSIG(status));
			}
			interrupt_end();
		}

		restore_registers(regs);

		/*Now we ended the syscall, so re-read local_using_sysemu.*/
		local_using_sysemu = get_using_sysemu();
		pt_syscall_parm = local_using_sysemu ? PTRACE_SYSEMU : PTRACE_SYSCALL;

		op = singlestepping(NULL) ? PTRACE_SINGLESTEP :
			pt_syscall_parm;

		err = ptrace(op, pid, 0, 0);
		if(err)
			panic("userspace - PTRACE_%s failed, "
			      "errno = %d\n",
			      local_using_sysemu ? "SYSEMU" : "SYSCALL", errno);
	}
}
开发者ID:GodFox,项目名称:magx_kernel_xpixl,代码行数:63,代码来源:process.c

示例6: parent

static void parent(pid_t child_pid)
{
	int status;
	bool exec_done = 0;

	while (1)
	{
		/* Wait for child status to change: */
		wait(&status);

		if (WIFEXITED(status)) {
//			printf("Child exit with status %d\n", WEXITSTATUS(status));
			exit(WEXITSTATUS(status));
		}
		if (WIFSIGNALED(status)) {
			fprintf(stderr, "Child exit due to signal %d\n", WTERMSIG(status));
			exit(0);
		}
		if (!WIFSTOPPED(status)) {
			fprintf(stderr, "wait() returned unhandled status 0x%x\n", status);
			exit(0);
		}
		if (WSTOPSIG(status) == SIGTRAP) {
			/* Note that there are *three* reasons why the child might stop
			 * with SIGTRAP:
			 *  1) syscall entry
			 *  2) syscall exit
			 *  3) child calls exec
			 */
			siginfo_t info;
			ptrace(PTRACE_GETSIGINFO, child_pid, 0, &info);
			if (info.si_code != SIGTRAP) {
				if (exec_done) {
					fprintf(stderr, "CHILD PERFORMED EXEC\n");
					kill(child_pid, SIGKILL);
					abort();
				} else {
					exec_done = 1;
				}
			} else {
#if 0
				sc_number = ptrace(PTRACE_PEEKUSER, child_pid, SC_NUMBER, NULL);
//				sc_retcode = ptrace(PTRACE_PEEKUSER, child_pid, SC_RETCODE, NULL);
//				printf("SIGTRAP: syscall %ld, rc = %ld\n", sc_number, sc_retcode);
				if (sc_number<0 || sc_number>512 || !is_allowed_syscall[sc_number]) {
					fprintf(stderr, "BLOCKED SYSCALL %ld\n", sc_number);
					kill(child_pid, SIGKILL);
					abort();
				}
#endif
			}
		} else if (WSTOPSIG(status) == 31) {
			long sc_number = ptrace(PTRACE_PEEKUSER, child_pid, SC_NUMBER, NULL);
			fprintf(stderr, "BLOCKED SYSCALL %ld\n", sc_number);
			kill(child_pid, SIGKILL);
			exit(1);
		} else {
			if (WSTOPSIG(status) != 19) {
				fprintf(stderr, "Child stopped due to signal %d\n", WSTOPSIG(status));
				kill(child_pid, SIGKILL);
				exit(1);
			}
		}
//		fflush(stdout);

		/* Resume child, requesting that it stops again on syscall enter/exit
		 * (in addition to any other reason why it might stop):
		 */
//		ptrace(PTRACE_SYSCALL, child_pid, NULL, NULL);
		ptrace(PTRACE_CONT, child_pid, NULL, NULL);
	}
}
开发者ID:dezgeg,项目名称:cses,代码行数:72,代码来源:restrict_syscalls.c

示例7: shmget


//.........这里部分代码省略.........

//for making sure the chilren exite good
#if 0
    int status; // catch the status of the child

    do  // in reality, mulptiple signals or exit status could come from the child
    {

        pid_t w = waitpid(pid, &status, WUNTRACED | WCONTINUED);
        if (w == -1)
        {
            std::cerr << "Error waiting for child process ("<< pid <<")" << std::endl;
            break;
        }

        if (WIFEXITED(status))
        {
            if (status > 0)
            {
                std::cerr << "Child process ("<< pid <<") exited with non-zero status of " << WEXITSTATUS(status) << std::endl;
                continue;
            }
            else
            {
                std::cout << "Child process ("<< pid <<") exited with status of " << WEXITSTATUS(status) << std::endl;
                continue;
            }
        }
        else if (WIFSIGNALED(status))
        {
            std::cout << "Child process ("<< pid <<") killed by signal (" << WTERMSIG(status) << ")" << std::endl;
            continue;
        }
        else if (WIFSTOPPED(status))
        {
            std::cout << "Child process ("<< pid <<") stopped by signal (" << WSTOPSIG(status) << ")" << std::endl;
            continue;
        }
        else if (WIFCONTINUED(status))
        {
            std::cout << "Child process ("<< pid <<") continued" << std::endl;
            continue;
        }
    }
    while (!WIFEXITED(status) && !WIFSIGNALED(status));

#endif




    int status;
    pid_t testingProc = 0;
    //wait for all the child procs to finish
    while(!minvan.empty()){
        //probably not enough checks for the procs waiting but
        // i'll come back later and fix it
        do{
            testingProc = wait(&status);

        }while (!WIFEXITED(status) && !WIFSIGNALED(status));

        minvan.erase(testingProc);
    }

开发者ID:samkreter,项目名称:High-Performance-Computing,代码行数:65,代码来源:vectorMatch.cpp

示例8: ATF_TC_BODY

ATF_TC_BODY(wait6_stop_and_go, tc)
{
	siginfo_t si;
	struct wrusage wru;
	int st;
	pid_t pid;
	static const struct rlimit rl = { 0, 0 };

	ATF_REQUIRE(setrlimit(RLIMIT_CORE, &rl) == 0);
	switch (pid = fork()) {
	case 0:
		sleep(100);
		/*FALLTHROUGH*/
	case -1:
		ATF_REQUIRE(pid > 0);
	default:
		ATF_REQUIRE(kill(pid, SIGSTOP) == 0);
		ATF_REQUIRE(wait6(P_PID, pid, &st, WSTOPPED, &wru, &si) == pid);
		ATF_REQUIRE(!WIFEXITED(st));
		ATF_REQUIRE(!WIFSIGNALED(st));
		ATF_REQUIRE(WIFSTOPPED(st) && WSTOPSIG(st) == SIGSTOP);
		ATF_REQUIRE(!WIFCONTINUED(st));
		ATF_REQUIRE(si.si_status == SIGSTOP);
		ATF_REQUIRE(si.si_pid == pid);
		ATF_REQUIRE(si.si_uid == getuid());
		ATF_REQUIRE(si.si_code == CLD_STOPPED);
#ifdef __NetBSD__
		printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
		    (uintmax_t)si.si_utime);
#endif

		ATF_REQUIRE(kill(pid, SIGCONT) == 0);
		ATF_REQUIRE(wait6(P_PID, pid, &st, WCONTINUED, &wru, &si) == pid);
		ATF_REQUIRE(!WIFEXITED(st));
		ATF_REQUIRE(!WIFSIGNALED(st));
		ATF_REQUIRE(WIFCONTINUED(st));
		ATF_REQUIRE(!WIFSTOPPED(st));
		ATF_REQUIRE(si.si_status == SIGCONT);
		ATF_REQUIRE(si.si_pid == pid);
		ATF_REQUIRE(si.si_uid == getuid());
		ATF_REQUIRE(si.si_code == CLD_CONTINUED);
#ifdef __NetBSD__
		printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
		    (uintmax_t)si.si_utime);
#endif

		ATF_REQUIRE(kill(pid, SIGQUIT) == 0);
		ATF_REQUIRE(wait6(P_PID, pid, &st, WEXITED, &wru, &si) == pid);
		ATF_REQUIRE(!WIFEXITED(st));
		ATF_REQUIRE(WIFSIGNALED(st) && WTERMSIG(st) == SIGQUIT);
		ATF_REQUIRE(!WIFSTOPPED(st));
		ATF_REQUIRE(!WIFCONTINUED(st));
		ATF_REQUIRE(si.si_status == SIGQUIT);
		ATF_REQUIRE(si.si_pid == pid);
		ATF_REQUIRE(si.si_uid == getuid());
		ATF_REQUIRE(si.si_code == CLD_KILLED);
#ifdef __NetBSD__
		printf("user: %ju system: %ju\n", (uintmax_t)si.si_utime,
		    (uintmax_t)si.si_utime);
#endif
		break;
	}
}
开发者ID:2trill2spill,项目名称:freebsd,代码行数:63,代码来源:t_wait.c

示例9: main

int main(int argc, char *argv[])
{
	int tdcount, tlimit, mlimit;
	char exename[1024], inputfile[1024];
	struct rlimit r;

	if (argc < 6)
	{
		printf("Usage: [id] [probid] [input] [time limit] [memory limit]\n");
		exit(RET_SE);
	}

	tlimit = atoi(argv[4]);
	mlimit = atoi(argv[5]);

	sprintf(exename, "./%s", argv[1]);
	strcpy(inputfile, argv[3]);


	if ((pid = fork()) == 0)
	{
		freopen("input.txt", "r", stdin);
		chdir("sandbox");
		chroot(".");
		freopen("output.txt", "w", stdout);
		setregid(99, 99);
		setreuid(99, 99);
		ptrace(PTRACE_TRACEME, 0, NULL, NULL);
		execl(exename, exename, NULL);
		exit(0);
	}
	
	signal(SIGALRM, timer);
	alarm(1);

	int stat, tmpmem, sig;
	for (;;)
	{
		wait4(pid, &stat, 0, &rinfo);
		if (WIFEXITED(stat))
		{
			puts("exited!\n");
			break;
		}
		else if (WIFSTOPPED(stat))
		{
			sig = WSTOPSIG(stat);
			if (sig == SIGTRAP)
			{
					if (checkSyscall() == RET_RF)
					{
						ptrace(PTRACE_KILL, pid, NULL, NULL);
						final_result(RET_RF);
					}
			}
			else if (sig == SIGUSR1)
			{
			}
			else
				printf("Stopped due to signal: %d\n", sig);
		}
		else if (WIFSIGNALED(stat))
		{
			//Runtime Error
			printf("Runtime Error. Received signal: %d\n", WTERMSIG(stat));
			final_result(RET_RE);
			break;
		}
		tmpmem = getMemory();
		if (tmpmem > maxmem) maxmem = tmpmem;

		if (maxmem > mlimit)
			final_result(RET_MLE);
		if (getRuntime() > tlimit)
		{
			ptrace(PTRACE_KILL, pid, NULL, NULL);
			final_result(RET_TLE);
		}
		ptrace(PTRACE_SYSCALL, pid, NULL, NULL);
	}
	final_result(RET_AC);
	
	return 0;
}
开发者ID:arbuztw,项目名称:judger,代码行数:84,代码来源:execute.c

示例10: f_pcntl_wifstopped

bool f_pcntl_wifstopped(int status) { return WIFSTOPPED(status);}
开发者ID:CSRedRat,项目名称:hiphop-php,代码行数:1,代码来源:ext_process.cpp

示例11: _stub

int
_stub (void *ep)
{
  void                     *bp_ip;
  long                    ip1, op1, op2;
  struct user_regs_struct regs;
  int                     status, cnt;

  printf ("%s", "0x00pf IbI Crypter Stub\n");

  // Start debugging!!!
  if ((_pid = fork ()) < 0) PERROR("fork:");

  if (_pid == 0) return 0;  // Child process just keeps running
  else
    {
      // Father starts debugging child
      if ((ptrace (PTRACE_ATTACH, _pid, NULL, NULL)) < 0) PERROR ("ptrace_attach:");
      printf ("%s", "+ Waiting for process...\n");
      wait (&status);

      bp_ip = ep;

      // Set breakpoint at get there...
      op1 = ptrace (PTRACE_PEEKTEXT, _pid, bp_ip);
      DPRINTF("BP: %p 1 Opcode: %lx\n", bp_ip, op1);
      if (ptrace (PTRACE_POKETEXT, _pid, bp_ip, 
		  (op1 & 0xFFFFFFFFFFFFFF00) | 0xcc) < 0) PERROR ("ptrace_poke:");

      // Run until breakpoint is reached.
      if (ptrace (PTRACE_CONT, _pid, 0, 0) < 0) PERROR("ptrace_cont:");
      wait (&status);
      
      ptrace (PTRACE_GETREGS, _pid, 0, &regs);
      DPRINTF ("Breakpoint reached: RIP: %llx\n", regs.rip);
      regs.rip--;
      ptrace (PTRACE_SETREGS, _pid, 0, &regs);

      // REstore opcode
      ptrace (PTRACE_POKETEXT, _pid, bp_ip, op1);

      // Start step by step debugging
      ip1 = (long) ep;
      cnt = 0;
      while (WIFSTOPPED (status))
	{
	  cnt ++;
	  // Read up to 16 bytes to get the longest instruction possible
	  // Decode and write back the decoded code to execute it
	  op1 = ptrace (PTRACE_PEEKTEXT, _pid, ip1);
	  op2 = ptrace (PTRACE_PEEKTEXT, _pid, ip1 + 8);
	  DPRINTF ("%lx :: OPCODES : %lx %lx\n", ip1, op1, op2);
	  
	  XOR(op1);
	  XOR(op2);

	  DPRINTF ("%lx :: DOPCODES: %lx %lx\n", ip1, op1, op2);

	  ptrace (PTRACE_POKETEXT, _pid, ip1, op1);
	  ptrace (PTRACE_POKETEXT, _pid, ip1 + 8, op2);

	  /* Make the child execute another instruction */
	  if (ptrace(PTRACE_SINGLESTEP, _pid, 0, 0) < 0) PERROR ("ptrace_singlestep:");
	  wait(&status);
	  
	  // Re-encode the instruction just executed so we do not have
	  // to count how many bytes got executed
	  XOR(op1);
	  XOR(op2);

	  ptrace (PTRACE_POKETEXT, _pid, ip1, op1);
	  ptrace (PTRACE_POKETEXT, _pid, ip1 + 8, op2);

	  // Get the new IP
	  ptrace (PTRACE_GETREGS, _pid, 0, &regs);
	  ip1 = regs.rip;

	  // If code is outside .secure section we stop debugging 
	  if ((void*)ip1 < secure_ptr || (void*)ip1 > secure_ptr + secure_len)
	    {
	      printf ("Leaving .secure section... %d instructions executed\n", cnt);
	      break;
	    }
	}

      ptrace (PTRACE_CONT, _pid, 0, 0);
      wait (&status);      
    }

  printf ("DONE\n");
  exit (1);
}
开发者ID:0x00pf,项目名称:0x00sec_code,代码行数:92,代码来源:stub.c

示例12: showjob

static void
showjob(struct output *out, struct job *jp, int mode)
{
	int procno;
	int st;
	struct procstat *ps;
	int col;
	char s[64];

#if JOBS
	if (mode & SHOW_PGID) {
		/* just output process (group) id of pipeline */
		outfmt(out, "%ld\n", (long)jp->ps->pid);
		return;
	}
#endif

	procno = jp->nprocs;
	if (!procno)
		return;

	if (mode & SHOW_PID)
		mode |= SHOW_MULTILINE;

	if ((procno > 1 && !(mode & SHOW_MULTILINE))
	    || (mode & SHOW_SIGNALLED)) {
		/* See if we have more than one status to report */
		ps = jp->ps;
		st = ps->status;
		do {
			int st1 = ps->status;
			if (st1 != st)
				/* yes - need multi-line output */
				mode |= SHOW_MULTILINE;
			if (st1 == -1 || !(mode & SHOW_SIGNALLED) || WIFEXITED(st1))
				continue;
			if (WIFSTOPPED(st1) || ((st1 = WTERMSIG(st1) & 0x7f)
			    && st1 != SIGINT && st1 != SIGPIPE))
				mode |= SHOW_ISSIG;

		} while (ps++, --procno);
		procno = jp->nprocs;
	}

	if (mode & SHOW_SIGNALLED && !(mode & SHOW_ISSIG)) {
		if (jp->state == JOBDONE && !(mode & SHOW_NO_FREE)) {
			TRACE(("showjob: freeing job %d\n", jp - jobtab + 1));
			freejob(jp);
		}
		return;
	}

	for (ps = jp->ps; --procno >= 0; ps++) {	/* for each process */
		if (ps == jp->ps)
			fmtstr(s, 16, "[%ld] %c ",
				(long)(jp - jobtab + 1),
#if JOBS
				jp == jobtab + curjob ? '+' :
				curjob != -1 && jp == jobtab +
					    jobtab[curjob].prev_job ? '-' :
#endif
				' ');
		else
			fmtstr(s, 16, "      " );
		col = strlen(s);
		if (mode & SHOW_PID) {
			fmtstr(s + col, 16, "%ld ", (long)ps->pid);
			     col += strlen(s + col);
		}
		if (ps->status == -1) {
			scopy("Running", s + col);
		} else if (WIFEXITED(ps->status)) {
			st = WEXITSTATUS(ps->status);
			if (st)
				fmtstr(s + col, 16, "Done(%d)", st);
			else
				fmtstr(s + col, 16, "Done");
		} else {
#if JOBS
			if (WIFSTOPPED(ps->status)) 
				st = WSTOPSIG(ps->status);
			else /* WIFSIGNALED(ps->status) */
#endif
				st = WTERMSIG(ps->status);
			st &= 0x7f;
			if (st < NSIG && sys_siglist[st])
				scopyn(sys_siglist[st], s + col, 32);
			else
				fmtstr(s + col, 16, "Signal %d", st);
			if (WCOREDUMP(ps->status)) {
				col += strlen(s + col);
				scopyn(" (core dumped)", s + col,  64 - col);
			}
		}
		col += strlen(s + col);
		outstr(s, out);
		do {
			outc(' ', out);
			col++;
		} while (col < 30);
//.........这里部分代码省略.........
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:101,代码来源:jobs.c

示例13: dowait

STATIC int
dowait(int flags, struct job *job)
{
	int pid;
	int status;
	struct procstat *sp;
	struct job *jp;
	struct job *thisjob;
	int done;
	int stopped;

	TRACE(("dowait(%x) called\n", flags));
	do {
		pid = waitproc(flags & WBLOCK, job, &status);
		TRACE(("wait returns pid %d, status %d\n", pid, status));
	} while (pid == -1 && errno == EINTR && pendingsigs == 0);
	if (pid <= 0)
		return pid;
	INTOFF;
	thisjob = NULL;
	for (jp = jobtab ; jp < jobtab + njobs ; jp++) {
		if (jp->used) {
			done = 1;
			stopped = 1;
			for (sp = jp->ps ; sp < jp->ps + jp->nprocs ; sp++) {
				if (sp->pid == -1)
					continue;
				if (sp->pid == pid) {
					TRACE(("Job %d: changing status of proc %d from 0x%x to 0x%x\n", jp - jobtab + 1, pid, sp->status, status));
					sp->status = status;
					thisjob = jp;
				}
				if (sp->status == -1)
					stopped = 0;
				else if (WIFSTOPPED(sp->status))
					done = 0;
			}
			if (stopped) {		/* stopped or done */
				int state = done ? JOBDONE : JOBSTOPPED;
				if (jp->state != state) {
					TRACE(("Job %d: changing state from %d to %d\n", jp - jobtab + 1, jp->state, state));
					jp->state = state;
#if JOBS
					if (done)
						set_curjob(jp, 0);
#endif
				}
			}
		}
	}

	if (thisjob && thisjob->state != JOBRUNNING) {
		int mode = 0;
		if (!rootshell || !iflag)
			mode = SHOW_SIGNALLED;
		if ((job == thisjob && (flags & WNOFREE) == 0) ||
		    (job != thisjob && (flags & WNOFREE) != 0))
			mode = SHOW_SIGNALLED | SHOW_NO_FREE;
		if (mode)
			showjob(out2, thisjob, mode);
		else {
			TRACE(("Not printing status, rootshell=%d, job=%p\n",
				rootshell, job));
			thisjob->changed = 1;
		}
	}

	INTON;
	return pid;
}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:70,代码来源:jobs.c

示例14: create_same_memory


//.........这里部分代码省略.........
			tst_resm(TINFO, "child %d continues...", k);
			exit(0);
		}
	}
	tst_resm(TINFO, "KSM merging...");
	snprintf(buf, BUFSIZ, "%s%s", PATH_KSM, "run");
	fd = open(buf, O_WRONLY);
	if (fd == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "open");
	if (write(fd, "1", 1) != 1)
		tst_brkm(TBROK|TERRNO, cleanup, "write");
	close(fd);
	snprintf(buf, BUFSIZ, "%s%s", PATH_KSM, "pages_to_scan");
	snprintf(buf2, BUFSIZ, "%ld", size * pages * num);
	fd = open(buf, O_WRONLY);
	if (fd == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "open");
	if (write(fd, buf2, strlen(buf2)) != strlen(buf2))
		tst_brkm(TBROK|TERRNO, cleanup, "write");
	close(fd);

	snprintf(buf, BUFSIZ, "%s%s", PATH_KSM, "sleep_millisecs");
	fd = open(buf, O_WRONLY);
	if (fd == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "open");
	if (write(fd, "0", 1) != 1)
		tst_brkm(TBROK|TERRNO, cleanup, "write");
	close(fd);

	tst_resm(TINFO, "wait for all children to stop.");
	for (k = 0; k < num; k++) {
		if (waitpid(child[k], &status, WUNTRACED) == -1)
			tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
		if (!WIFSTOPPED(status))
			tst_brkm(TBROK, cleanup, "child %d was not stopped.",
				k);
	}
	tst_resm(TINFO, "resume all children.");
	for (k = 0; k < num; k++) {
		if (kill(child[k], SIGCONT) == -1)
			tst_brkm(TBROK|TERRNO, cleanup, "kill child[%d]", k);
	}
	group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);

	tst_resm(TINFO, "wait for child 1 to stop.");
	if (waitpid(child[1], &status, WUNTRACED) == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
	if (!WIFSTOPPED(status))
		tst_brkm(TBROK, cleanup, "child 1 was not stopped.");

	/* Child 1 changes all pages to 'b'. */
	tst_resm(TINFO, "resume child 1.");
	if (kill(child[1], SIGCONT) == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "kill");
	group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);

	tst_resm(TINFO, "wait for child 1 to stop.");
	if (waitpid(child[1], &status, WUNTRACED) == -1)
		tst_brkm(TBROK|TERRNO, cleanup, "waitpid");
	if (!WIFSTOPPED(status))
		tst_brkm(TBROK, cleanup, "child 1 was not stopped.");

	/* All children change pages to 'd'. */
	tst_resm(TINFO, "resume all children.");
	for (k = 0; k < num; k++) {
		if (kill(child[k], SIGCONT) == -1)
开发者ID:sconklin,项目名称:ltp-tools,代码行数:67,代码来源:mem.c

示例15: main


//.........这里部分代码省略.........
	if ( use_root ) {
		/* Small security issue: when running setuid-root, people can find
		   out which directories exist from error message. */
		if ( chdir(rootdir) ) error(errno,"cannot chdir to `%s'",rootdir);

		/* Get absolute pathname of rootdir, by reading it. */
		if ( getcwd(cwd,MAXPATHLEN)==NULL ) error(errno,"cannot get directory");
		if ( cwd[strlen(cwd)-1]!='/' ) strcat(cwd,"/");

		/* Canonicalize CHROOT_PREFIX: the use of NULL below is a GNU
		   extension, recommended for security */
		if ( (path = realpath(CHROOT_PREFIX,NULL))==NULL ) {
			error(errno,"cannot canonicalize path '%s'",CHROOT_PREFIX);
		}
		
		/* Check that we are within prescribed path. */
		if ( strncmp(cwd,path,strlen(path))!=0 ) {
			error(0,"invalid root: must be within `%s'",path);
		}
		free(path);
		
		if ( chroot(".") ) error(errno,"cannot change root to `%s'",cwd);
		verbose("using root-directory `%s'",cwd);
	}
	
	/* Set user-id (must be root for this). */
	if ( use_user ) {
		if ( setuid(runuid) ) error(errno,"cannot set user ID to `%d'",runuid);
		verbose("using user ID `%d'",runuid);
	} else {
		/* Reset effective uid to real uid, to increase security
		   when program is run setuid */
		if ( setuid(getuid()) ) error(errno,"cannot set real user ID");
		verbose("using real uid `%d' as effective uid",getuid());
	}
	if ( geteuid()==0 || getuid()==0 ) error(0,"root privileges not dropped");

	/* Open output file for writing running time to */
	if ( use_output ) {
		outputfile = fopen(outputfilename,"w");
		if ( outputfile==NULL ) error(errno,"cannot open `%s'",outputfilename);
		verbose("using file `%s' to write runtime to",outputfilename);
	}
	
	switch ( child_pid = fork() ) {
	case -1: /* error */
		error(errno,"cannot fork");
		
	case  0: /* run controlled command */
		/* Run the command in a separate process group so that the command
		   and all its children can be killed off with one signal. */
		setsid();
		execvp(cmdname,cmdargs);
		error(errno,"cannot start `%s'",cmdname);
		
	default: /* become watchdog */
		if ( gettimeofday(&starttime,NULL) ) error(errno,"getting time");

		/* unmask all signals */
		memset(&newmask, 0, sizeof(newmask));
		if ( sigprocmask(SIG_SETMASK, &newmask, &oldmask)!=0 ) {
			error(errno,"unmasking signals");
		}

		signal(SIGTERM,terminate);
		
		if ( use_time ) {
			signal(SIGALRM,terminate);
			alarm(runtime);
			verbose("using timelimit of %d seconds",runtime);
		}

		/* Wait for the child command to finish */
		while ( (pid = wait(&status))!=-1 && pid!=child_pid );
		if ( pid!=child_pid ) error(errno,"waiting on child");

		outputtime();

		/* Test whether command has finished abnormally */
		if ( ! WIFEXITED(status) ) {
			if ( WIFSIGNALED(status) ) {
				warning("command terminated with signal %d",WTERMSIG(status));
				return 128+WTERMSIG(status);
			}
			if ( WIFSTOPPED(status) ) {
				warning("command stopped with signal %d",WSTOPSIG(status));
				return 128+WSTOPSIG(status);
			}
			error(0,"command exit status unknown: %d",status);
		}
		
		/* Return the exitstatus of the command */
		exitcode = WEXITSTATUS(status);
		if ( exitcode!=0 ) verbose("command exited with exitcode %d",exitcode);
		return exitcode; 
	}

	/* This should never be reached */
	error(0,"unexpected end of program");
}
开发者ID:jlsa,项目名称:justitia,代码行数:101,代码来源:runguard.c


注:本文中的WIFSTOPPED函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。