Ejemplo n.º 1
0
static void
dt_proc_bpdestroy(dt_proc_t *dpr, int delbkpts)
{
#if defined(sun)
	int state = Pstate(dpr->dpr_proc);
#else
	int state = proc_state(dpr->dpr_proc);
#endif
	dt_bkpt_t *dbp, *nbp;

	assert(DT_MUTEX_HELD(&dpr->dpr_lock));

	for (dbp = dt_list_next(&dpr->dpr_bps); dbp != NULL; dbp = nbp) {
printf("%s:%s(%d): DOODAD\n",__FUNCTION__,__FILE__,__LINE__);
#ifdef DOODAD
		if (delbkpts && dbp->dbp_active &&
		    state != PS_LOST && state != PS_UNDEAD) {
			(void) Pdelbkpt(dpr->dpr_proc,
			    dbp->dbp_addr, dbp->dbp_instr);
		}
#endif
		nbp = dt_list_next(dbp);
		dt_list_delete(&dpr->dpr_bps, dbp);
		dt_free(dpr->dpr_hdl, dbp);
	}
}
Ejemplo n.º 2
0
static int proc_stopped(int pid)
{
    int c = proc_state(pid);
    if (c == -1)
        return -1;

    return (c == 't' || c == 'T');
}
Ejemplo n.º 3
0
char *get_thread_states(const int *tids, int n)
{
    int i;
    char *res = calloc(1, n);

    for (i = 0; i < n; ++i) {
        int state = proc_state(tids[i]);
        if (state < 0) {
            fprintf(stderr, "warning: could not get state of thread %d\n",
                    tids[i]);
            res[i] = '?';
            continue;
        }
        res[i] = state;
    }

    return res;
}
Ejemplo n.º 4
0
/**
 * Starts a program
 */
void console_start(char *dir, char *command) {
    memset(senddir, 0, 64);
    strcpy(senddir, dir);
    strcat(senddir, "/");
    strcat(senddir, get_argument(command, 1));
    // Cut the arguments from the path
    if(get_argument(senddir, 1)) {
        strncpy(senddir, senddir, strlen(senddir) - strlen(get_argument(senddir, 1)) - 1);
    }

    char *arguments = kmalloc(128);
    memset(arguments, 0, 128);
    strcpy(arguments, get_argument(command, 2));

    int procn = start_proc(senddir, arguments);
    if(procn != PROC_STOPPED) {
        while(proc_state(procn) != PROC_STOPPED);
        remove_proc(procn);
        printk("\n");
    }
}
Ejemplo n.º 5
0
/*
 * Added cpu_id to running processes, add 'ready' (to run) state
 */
static char *
format_state(struct prpsinfo * pp)

{
	static char state_str[16];
	int			state = proc_state(pp);

	if (state == S_RUNNING)
	{
		/*
		 * Alert: 6.2 (MP only?) binary incompatibility pp->pr_sonproc
		 * apparently (?) has a different offset on 6.2 machines... I've seen
		 * cases where a 6.4 compiled pg_top running on 6.2 printed a garbage
		 * CPU-id. To be safe, I print the CPU-id only if it falls within
		 * range [0..numcpus-1]
		 */
		sprintf(state_str, "run/%d", pp->pr_sonproc);
		return state_str;
	}

	/* default */
	return state_abbrev[state];
}
Ejemplo n.º 6
0
/*ARGSUSED*/
static void
prochandler(struct ps_prochandle *P, const char *msg, void *arg)
{
#if defined(sun)
	const psinfo_t *prp = Ppsinfo(P);
	int pid = Pstatus(P)->pr_pid;
	char name[SIG2STR_MAX];
#else
	int wstatus = proc_getwstat(P);
	int pid = proc_getpid(P);
#endif

	if (msg != NULL) {
		notice("pid %d: %s\n", pid, msg);
		return;
	}

#if defined(sun)
	switch (Pstate(P)) {
#else
	switch (proc_state(P)) {
#endif
	case PS_UNDEAD:
#if defined(sun)
		/*
		 * Ideally we would like to always report pr_wstat here, but it
		 * isn't possible given current /proc semantics.  If we grabbed
		 * the process, Ppsinfo() will either fail or return a zeroed
		 * psinfo_t depending on how far the parent is in reaping it.
		 * When /proc provides a stable pr_wstat in the status file,
		 * this code can be improved by examining this new pr_wstat.
		 */
		if (prp != NULL && WIFSIGNALED(prp->pr_wstat)) {
			notice("pid %d terminated by %s\n", pid,
			    proc_signame(WTERMSIG(prp->pr_wstat),
			    name, sizeof (name)));
#else
		if (WIFSIGNALED(wstatus)) {
			notice("pid %d terminated by %d\n", pid,
			    WTERMSIG(wstatus));
#endif
#if defined(sun)
		} else if (prp != NULL && WEXITSTATUS(prp->pr_wstat) != 0) {
			notice("pid %d exited with status %d\n",
			    pid, WEXITSTATUS(prp->pr_wstat));
#else
		} else if (WEXITSTATUS(wstatus) != 0) {
			notice("pid %d exited with status %d\n",
			    pid, WEXITSTATUS(wstatus));
#endif
		} else {
			notice("pid %d has exited\n", pid);
		}
		g_pslive--;
		break;

	case PS_LOST:
		notice("pid %d exec'd a set-id or unobservable program\n", pid);
		g_pslive--;
		break;
	}
}

/*ARGSUSED*/
static int
errhandler(const dtrace_errdata_t *data, void *arg)
{
	error(data->dteda_msg);
	return (DTRACE_HANDLE_OK);
}

/*ARGSUSED*/
static int
drophandler(const dtrace_dropdata_t *data, void *arg)
{
	error(data->dtdda_msg);
	return (DTRACE_HANDLE_OK);
}
Ejemplo n.º 7
0
caddr_t
get_process_info(struct system_info * si, struct process_select * sel, int compare_index)

{
	int			i,
				total_procs,
				active_procs;
	struct prpsinfo **prefp;
	struct prpsinfo *pp;
	int			show_uid;
	static char first_screen = 1;

	/* read all the proc structures */
	getptable(pbase);

	/* get a pointer to the states summary array */
	si->procstates = process_states;

	/* set up flags which define what we are going to select */
	show_uid = sel->uid != -1;

	/* count up process states and get pointers to interesting procs */
	total_procs = 0;
	active_procs = 0;
	(void) memset(process_states, 0, sizeof(process_states));
	prefp = pref;

	for (pp = pbase, i = 0; i < nproc; pp++, i++)
	{
		/*
		 * Place pointers to each valid proc structure in pref[]. Process
		 * slots that are actually in use have a non-zero status field.
		 * Processes with SSYS set are system processes---these get ignored
		 * unless show_system is set. Ariel: IRIX 6.4 had to redefine "system
		 * processes" They do not exist outside the kernel in new kernels. Now
		 * defining as uid==0 and ppid==1 (init children)
		 */
		if (pp->pr_state &&
			(sel->system || !(pp->pr_uid == 0 && pp->pr_ppid == 1)))
		{
			total_procs++;
			process_states[proc_state(pp)]++;

			/*
			 * zombies are actually interesting (to avoid) although they are
			 * not active, so I leave them displayed.
			 */
			if (				/* (! pp->pr_zomb) && */
				(sel->idle || IS_ACTIVE(pp)) &&
				(!show_uid || pp->pr_uid == (uid_t) sel->uid))
			{
				*prefp++ = pp;
				active_procs++;
			}
		}
	}
	first_screen = 0;

	/* if requested, sort the "interesting" processes */
	qsort((char *) pref, active_procs, sizeof(struct prpsinfo *),
		  proc_compares[compare_index]);

	/* remember active and total counts */
	si->p_total = total_procs;
	si->p_active = active_procs;

	/* pass back a handle */
	handle.next_proc = pref;
	handle.remaining = active_procs;
	return ((caddr_t) & handle);
}