Ejemplo n.º 1
0
gboolean
ck_process_stat_new_for_unix_pid (pid_t           pid,
                                  CkProcessStat **stat,
                                  GError        **error)
{
        gboolean       res;
        CkProcessStat *proc;

        g_return_val_if_fail (pid > 1, FALSE);

        if (stat == NULL) {
                return FALSE;
        }

        proc = g_new0 (CkProcessStat, 1);
        proc->pid = pid;
        res = stat2proc (pid, proc);
        if (res) {
                *stat = proc;
        } else {
                *stat = NULL;
        }

        return res;
}
Ejemplo n.º 2
0
gboolean
ck_process_stat_new_for_unix_pid (pid_t           pid,
                                  CkProcessStat **stat,
                                  GError        **error)
{
        char        *path;
        char        *contents;
        gsize        length;
        gboolean     res;
        GError      *local_error;
        CkProcessStat *proc;

        g_return_val_if_fail (pid > 1, FALSE);

        if (stat == NULL) {
                return FALSE;
        }

        proc = g_new0 (CkProcessStat, 1);
        proc->pid = pid;
        res = stat2proc (pid, proc);
        if (res) {
                *stat = proc;
        } else {
                g_propagate_error (error, local_error);
                *stat = NULL;
        }

        return res;
}
Ejemplo n.º 3
0
int main(int argc, char *argv[])
{
	arg_parse(argc, argv);

	page_shift = __getpageshift();

#if 0
	choose_dimensions();
#endif
	if (!old_h_option) {
		const char *head;
		switch (ps_format) {
		default:	/* can't happen */
		case 0:
			head = "  PID TTY         TIME CMD";
			break;
		case 'l':
			head =
			    "  F S   UID   PID  PPID  C PRI  NI ADDR SZ WCHAN    TTY       TIME CMD";
			break;
		case 'f':
			head =
			    "  UID   PID  PPID  C STIME   TTY       TIME CMD";
			break;
		case 'j':
			head = "  PID  PGID   SID TTY         TIME CMD";
			break;
		case 'u' | 0x80:
			head =
			    "  UID   PID %CPU %MEM   VSZ   RSS   TTY   S START     TIME COMMAND";
			break;
		case 'v' | 0x80:
			head =
			    "  PID   TTY   S     TIME  MAJFL TRS DRS   RSS %MEM COMMAND";
			break;
		case 'j' | 0x80:
			head =
			    " PPID   PID  PGID   SID   TTY   TPGID S   UID     TIME COMMAND";
			break;
		case 'l' | 0x80:
			head =
			    "  F   UID   PID  PPID PRI  NI   VSZ  RSS WCHAN  S   TTY       TIME COMMAND";
			break;
		}
		printf("%s\n", head);
	}
	if (want_one_pid) {
		if (stat2proc(want_one_pid))
			print_proc();
		else
			exit(1);
	} else {
		struct dirent *ent;	/* dirent handle */
		DIR *dir;
		int ouruid;
		int found_a_proc;
		found_a_proc = 0;
		ouruid = getuid();
		dir = opendir("/proc");
		if (!dir)
			exit(1);
		while ((ent = readdir(dir))) {
			if (*ent->d_name < '0' || *ent->d_name > '9')
				continue;
			if (!stat2proc(atoi(ent->d_name)))
				continue;
			if (want_one_command) {
				if (strcmp(want_one_command, P_cmd))
					continue;
			} else {
				if (!select_notty && P_tty == -1)
					continue;
				if (!select_all && P_euid != ouruid)
					continue;
			}
			found_a_proc++;
			print_proc();
		}
		closedir(dir);
		exit(!found_a_proc);
	}
	return 0;
}