diff -C 2 -r -N bin/ps.orig/ps.1 bin/ps/ps.1
*** bin/ps.orig/ps.1	Fri Feb  1 14:09:30 2002
--- bin/ps/ps.1	Mon Jul  1 22:40:38 2002
***************
*** 41,49 ****
  .Sh SYNOPSIS
  .Nm
! .Op Fl aCcefhjlmrSTuvwx
  .Op Fl M Ar core
  .Op Fl N Ar system
  .Op Fl O Ar fmt
  .Op Fl o Ar fmt
  .Op Fl p Ar pid
  .Op Fl t Ar tty
--- 41,50 ----
  .Sh SYNOPSIS
  .Nm
! .Op Fl aCcefhHjlmrSTuvwx
  .Op Fl M Ar core
  .Op Fl N Ar system
  .Op Fl O Ar fmt
  .Op Fl o Ar fmt
+ .Op Fl J Ar jail
  .Op Fl p Ar pid
  .Op Fl t Ar tty
***************
*** 97,103 ****
--- 98,108 ----
  Repeat the information header as often as necessary to guarantee one
  header per page of information.
+ .It Fl H
+ When running jails only displays processes belonging to the host system.
  .It Fl j
  Print information associated with the following keywords:
  user, pid, ppid, pgid, sess, jobc, state, tt, time and command.
+ .It Fl J
+ Limit processes displayed to the jail specified.
  .It Fl L
  List the set of available keywords.
diff -C 2 -r -N bin/ps.orig/ps.c bin/ps/ps.c
*** bin/ps.orig/ps.c	Fri Feb  1 14:09:30 2002
--- bin/ps/ps.c	Mon Jul  1 22:41:49 2002
***************
*** 104,107 ****
--- 104,111 ----
  static uid_t	*getuids(const char *, int *);
  
+ static int	getpidjail(pid_t, char*);
+ #define 	JAIL_BUFF_SIZE		MAXHOSTNAMELEN + 2
+ #define 	PROC_STATUS_PATH	"/proc/%d/status"
+ 
  char dfmt[] = "pid tt state time command";
  char jfmt[] = "user pid ppid pgid sess jobc state tt time command";
***************
*** 125,128 ****
--- 129,134 ----
  	pid_t pid;
  	uid_t *uids;
+ 	char *jailName = NULL;	/* Only show processes in this jail */
+ 	int jailHost = 0; 	/* Only show processes in host system */
  	int all, ch, flag, i, fmt, lineno, nentries, dropgid;
  	int prtheader, wflag, what, xflg, uid, nuids;
***************
*** 151,157 ****
  	while ((ch = getopt(argc, argv,
  #if defined(LAZY_PS)
! 	    "aCcefghjLlM:mN:O:o:p:rSTt:U:uvwx")) != -1)
  #else
! 	    "aCceghjLlM:mN:O:o:p:rSTt:U:uvwx")) != -1)
  #endif
  		switch((char)ch) {
--- 157,163 ----
  	while ((ch = getopt(argc, argv,
  #if defined(LAZY_PS)
! 	    "aCcefgHhJ:jLlM:mN:O:o:p:rSTt:U:uvwx")) != -1)
  #else
! 	    "aCcegHhJ:jLlM:mN:O:o:p:rSTt:U:uvwx")) != -1)
  #endif
  		switch((char)ch) {
***************
*** 173,176 ****
--- 179,185 ----
  			prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
  			break;
+ 		case 'H':
+ 			jailHost = 1;
+ 			break;
  		case 'j':
  			parsefmt(jfmt);
***************
*** 178,181 ****
--- 187,193 ----
  			jfmt[0] = '\0';
  			break;
+ 		case 'J':
+ 			jailName = optarg;
+ 			break;
  		case 'L':
  			showkey();
***************
*** 363,366 ****
--- 375,401 ----
  	 */
  	for (i = lineno = 0; i < nentries; i++) {
+ 
+ 		/* Nate: If limiting to jails in the host ... */
+ 		if (jailHost) {
+ 			struct proc *p = KI_PROC(&kinfo[i]);
+ 			if(!p || p->p_prison || p->p_flag & P_JAILED)
+ 				continue;
+ 		}
+ 
+ 		/* Nate: If limiting to a certain jail then check */
+ 		else if (jailName) {
+ 			struct proc *p = KI_PROC(&kinfo[i]);
+ 			char pidjail[JAIL_BUFF_SIZE];
+ 
+ 			if(!p || !p->p_prison || !(p->p_flag & P_JAILED))
+ 				continue;
+ 
+ 			if(getpidjail(p->p_pid, pidjail) < 0)
+ 				continue;
+ 
+ 			if(strcmp(jailName, pidjail))
+ 				continue;
+ 		}
+ 
  		if (xflg == 0 && (KI_EPROC(&kinfo[i])->e_tdev == NODEV ||
  		    (KI_PROC(&kinfo[i])->p_flag & P_CONTROLT ) == 0))
***************
*** 391,394 ****
--- 426,473 ----
  }
  
+ int
+ getpidjail(pid_t pid, char* buff)
+ {
+ 	int fd;
+ 	size_t bytes;
+ 	off_t off;
+ 	
+ 	/* Format the file name */
+ 	if(snprintf(buff, JAIL_BUFF_SIZE, PROC_STATUS_PATH, pid))
+ 	{
+ 		/* Open the file */
+ 		if((fd = open(buff, O_RDONLY)) >= 0)
+ 		{
+ 			/* Seek to the last bit */
+ 			off = lseek(fd, SEEK_END, 0);
+ 			
+ 			if(off != -1)
+ 			{
+ 				off -= JAIL_BUFF_SIZE;
+ 				if(off < 0) off = 0;
+ 				lseek(fd, SEEK_SET, off);
+ 
+ 				if((bytes = read(fd, buff, JAIL_BUFF_SIZE - 1)) > 0)
+ 				{
+ 					/* Okay now jailname should be the last token */
+ 					while(isspace(buff[bytes - 1]))
+ 						bytes--;
+ 
+ 					buff[bytes] = 0;
+ 
+ 					while(!isspace(buff[bytes - 1]))
+ 						bytes--;
+ 
+ 					memmove(buff, buff + bytes, JAIL_BUFF_SIZE - bytes);
+ 					return 0;
+ 
+ 				}
+ 			}
+ 		}
+ 	}
+ 
+ 	return -1;
+ }
+ 
  uid_t *
  getuids(const char *arg, int *nuids)
***************
*** 637,641 ****
  
  	(void)fprintf(stderr, "%s\n%s\n%s\n",
! 	    "usage: ps [-aChjlmrSTuvwx] [-O|o fmt] [-p pid] [-t tty] [-U user]",
  	    "          [-M core] [-N system]",
  	    "       ps [-L]");
--- 716,720 ----
  
  	(void)fprintf(stderr, "%s\n%s\n%s\n",
! 	    "usage: ps [-aChHjlmrSTuvwx] [-J jail] [-O|o fmt] [-p pid] [-t tty] [-U user]",
  	    "          [-M core] [-N system]",
  	    "       ps [-L]");
