822 lines · 22.6 KB · C
RawDownload
		 *		 * The only exception is if the task is core dumping because		 * a program is not able to use ptrace(2) in that case. It is		 * safe because the task has stopped executing permanently.		 */		if (permitted && (task->flags & (PF_EXITING|PF_DUMPCORE|PF_POSTCOREDUMP))) {			if (try_get_task_stack(task)) {				eip = KSTK_EIP(task);				esp = KSTK_ESP(task);				put_task_stack(task);			}		}	} 	sigemptyset(&sigign);	sigemptyset(&sigcatch); 	if (lock_task_sighand(task, &flags)) {		if (sig->tty) {			struct pid *pgrp = tty_get_pgrp(sig->tty);			tty_pgrp = pid_nr_ns(pgrp, ns);			put_pid(pgrp);			tty_nr = new_encode_dev(tty_devnum(sig->tty));		} 		num_threads = get_nr_threads(task);		collect_sigign_sigcatch(task, &sigign, &sigcatch); 		rsslim = READ_ONCE(sig->rlim[RLIMIT_RSS].rlim_cur); 		if (whole) {			if (sig->flags & (SIGNAL_GROUP_EXIT | SIGNAL_STOP_STOPPED))				exit_code = sig->group_exit_code;		} 		sid = task_session_nr_ns(task, ns);		ppid = task_ppid_nr_ns(task, ns);		pgid = task_pgrp_nr_ns(task, ns); 		unlock_task_sighand(task, &flags);	} 	if (permitted && (!whole || num_threads < 2))		wchan = !task_is_running(task); 	scoped_guard(rcu) {		scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) {			cmin_flt = sig->cmin_flt;			cmaj_flt = sig->cmaj_flt;			cutime = sig->cutime;			cstime = sig->cstime;			cgtime = sig->cgtime; 			if (whole) {				struct task_struct *t; 				min_flt = sig->min_flt;				maj_flt = sig->maj_flt;				gtime = sig->gtime; 				__for_each_thread(sig, t) {					min_flt += t->min_flt;					maj_flt += t->maj_flt;					gtime += task_gtime(t);				}			}		}	} 	if (whole) {		thread_group_cputime_adjusted(task, &utime, &stime);	} else {		task_cputime_adjusted(task, &utime, &stime);		min_flt = task->min_flt;		maj_flt = task->maj_flt;		gtime = task_gtime(task);	} 	/* scale priority and nice values from timeslices to -20..20 */	/* to make it look like a "normal" Unix priority/nice value  */	priority = task_prio(task);	nice = task_nice(task); 	/* apply timens offset for boottime and convert nsec -> ticks */	start_time =		nsec_to_clock_t(timens_add_boottime_ns(task->start_boottime)); 	seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));	seq_puts(m, " (");	proc_task_name(m, task, false);	seq_puts(m, ") ");	seq_putc(m, state);	seq_put_decimal_ll(m, " ", ppid);	seq_put_decimal_ll(m, " ", pgid);	seq_put_decimal_ll(m, " ", sid);	seq_put_decimal_ll(m, " ", tty_nr);	seq_put_decimal_ll(m, " ", tty_pgrp);	seq_put_decimal_ull(m, " ", task->flags);	seq_put_decimal_ull(m, " ", min_flt);	seq_put_decimal_ull(m, " ", cmin_flt);	seq_put_decimal_ull(m, " ", maj_flt);	seq_put_decimal_ull(m, " ", cmaj_flt);	seq_put_decimal_ull(m, " ", nsec_to_clock_t(utime));	seq_put_decimal_ull(m, " ", nsec_to_clock_t(stime));	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cutime));	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cstime));	seq_put_decimal_ll(m, " ", priority);	seq_put_decimal_ll(m, " ", nice);	seq_put_decimal_ll(m, " ", num_threads);	seq_put_decimal_ull(m, " ", 0);	seq_put_decimal_ull(m, " ", start_time);	seq_put_decimal_ull(m, " ", vsize);	seq_put_decimal_ull(m, " ", mm ? get_mm_rss(mm) : 0);	seq_put_decimal_ull(m, " ", rsslim);	seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->start_code : 1) : 0);	seq_put_decimal_ull(m, " ", mm ? (permitted ? mm->end_code : 1) : 0);	seq_put_decimal_ull(m, " ", (permitted && mm) ? mm->start_stack : 0);	seq_put_decimal_ull(m, " ", esp);	seq_put_decimal_ull(m, " ", eip);	/* The signal information here is obsolete.	 * It must be decimal for Linux 2.0 compatibility.	 * Use /proc/#/status for real-time signals.	 */	seq_put_decimal_ull(m, " ", task->pending.signal.sig[0] & 0x7fffffffUL);	seq_put_decimal_ull(m, " ", task->blocked.sig[0] & 0x7fffffffUL);	seq_put_decimal_ull(m, " ", sigign.sig[0] & 0x7fffffffUL);	seq_put_decimal_ull(m, " ", sigcatch.sig[0] & 0x7fffffffUL); 	/*	 * We used to output the absolute kernel address, but that's an	 * information leak - so instead we show a 0/1 flag here, to signal	 * to user-space whether there's a wchan field in /proc/PID/wchan.	 *	 * This works with older implementations of procps as well.	 */	seq_put_decimal_ull(m, " ", wchan); 	seq_put_decimal_ull(m, " ", 0);	seq_put_decimal_ull(m, " ", 0);	seq_put_decimal_ll(m, " ", task->exit_signal);	seq_put_decimal_ll(m, " ", task_cpu(task));	seq_put_decimal_ull(m, " ", task->rt_priority);	seq_put_decimal_ull(m, " ", task->policy);	seq_put_decimal_ull(m, " ", delayacct_blkio_ticks(task));	seq_put_decimal_ull(m, " ", nsec_to_clock_t(gtime));	seq_put_decimal_ll(m, " ", nsec_to_clock_t(cgtime)); 	if (mm && permitted) {		seq_put_decimal_ull(m, " ", mm->start_data);		seq_put_decimal_ull(m, " ", mm->end_data);		seq_put_decimal_ull(m, " ", mm->start_brk);		seq_put_decimal_ull(m, " ", mm->arg_start);		seq_put_decimal_ull(m, " ", mm->arg_end);		seq_put_decimal_ull(m, " ", mm->env_start);		seq_put_decimal_ull(m, " ", mm->env_end);	} else		seq_puts(m, " 0 0 0 0 0 0 0"); 	if (permitted)		seq_put_decimal_ll(m, " ", exit_code);	else		seq_puts(m, " 0"); 	seq_putc(m, '\n');	up_read(&task->signal->exec_update_lock);	if (mm)		mmput(mm);	return 0;} int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,			struct pid *pid, struct task_struct *task){	return do_task_stat(m, ns, pid, task, 0);} int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,			struct pid *pid, struct task_struct *task){	return do_task_stat(m, ns, pid, task, 1);} int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,			struct pid *pid, struct task_struct *task){	struct mm_struct *mm = get_task_mm(task); 	if (mm) {		unsigned long size;		unsigned long resident = 0;		unsigned long shared = 0;		unsigned long text = 0;		unsigned long data = 0; 		size = task_statm(mm, &shared, &text, &data, &resident);		mmput(mm); 		/*		 * For quick read, open code by putting numbers directly		 * expected format is		 * seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",		 *               size, resident, shared, text, data);		 */		seq_put_decimal_ull(m, "", size);		seq_put_decimal_ull(m, " ", resident);		seq_put_decimal_ull(m, " ", shared);		seq_put_decimal_ull(m, " ", text);		seq_put_decimal_ull(m, " ", 0);		seq_put_decimal_ull(m, " ", data);		seq_put_decimal_ull(m, " ", 0);		seq_putc(m, '\n');	} else {		seq_write(m, "0 0 0 0 0 0 0\n", 14);	}	return 0;} #ifdef CONFIG_PROC_CHILDRENstatic struct pid *get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos){	struct task_struct *start, *task;	struct pid *pid = NULL; 	read_lock(&tasklist_lock); 	start = pid_task(proc_pid(inode), PIDTYPE_PID);	if (!start)		goto out; 	/*	 * Lets try to continue searching first, this gives	 * us significant speedup on children-rich processes.	 */	if (pid_prev) {		task = pid_task(pid_prev, PIDTYPE_PID);		if (task && task->real_parent == start &&		    !(list_empty(&task->sibling))) {			if (list_is_last(&task->sibling, &start->children))				goto out;			task = list_first_entry(&task->sibling,						struct task_struct, sibling);			pid = get_pid(task_pid(task));			goto out;		}	} 	/*	 * Slow search case.	 *	 * We might miss some children here if children	 * are exited while we were not holding the lock,	 * but it was never promised to be accurate that	 * much.	 *	 * "Just suppose that the parent sleeps, but N children	 *  exit after we printed their tids. Now the slow paths	 *  skips N extra children, we miss N tasks." (c)	 *	 * So one need to stop or freeze the leader and all	 * its children to get a precise result.	 */	list_for_each_entry(task, &start->children, sibling) {		if (pos-- == 0) {			pid = get_pid(task_pid(task));			break;		}	} out:	read_unlock(&tasklist_lock);	return pid;} static int children_seq_show(struct seq_file *seq, void *v){	struct inode *inode = file_inode(seq->file); 	seq_printf(seq, "%d ", pid_nr_ns(v, proc_pid_ns(inode->i_sb)));	return 0;} static void *children_seq_start(struct seq_file *seq, loff_t *pos){	return get_children_pid(file_inode(seq->file), NULL, *pos);} static void *children_seq_next(struct seq_file *seq, void *v, loff_t *pos){	struct pid *pid; 	pid = get_children_pid(file_inode(seq->file), v, *pos + 1);	put_pid(v); 	++*pos;	return pid;} static void children_seq_stop(struct seq_file *seq, void *v){	put_pid(v);} static const struct seq_operations children_seq_ops = {	.start	= children_seq_start,	.next	= children_seq_next,	.stop	= children_seq_stop,	.show	= children_seq_show,}; static int children_seq_open(struct inode *inode, struct file *file){	return seq_open(file, &children_seq_ops);} const struct file_operations proc_tid_children_operations = {	.open    = children_seq_open,	.read    = seq_read,	.llseek  = seq_lseek,	.release = seq_release,};#endif /* CONFIG_PROC_CHILDREN */

Lines 501–822 of 822. Previous lines

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t