jails Question re: ps(1) and -J option

Maybe I'm confused, but I can't seem to get the -J option of ps(1) to work for me.

With four jails running I get the same (amount) of output from ps, no matter whether I omit -J, or use any one of the four jail ids:

Code:
# for j in '' $(jls jid); do ps ${j:+-J$j} -auxww | wc -l; done
     208
     208
     208
     208
     208

I would expect to see a number smaller than 208 on the 2nd through 5th lines of output.

What am I doing wrong?
 
I guess it's because -a conflicts with -J. The fix is to not use -a when -J is in use:

Code:
# for j in '' $(jls jid); do j=${j:+-J$j}; j=${j:--a}; ps ${j} -uxww | wc -l; d
one
     210
      29
      16
       5
       1
 
I kinda wish -a meant "all processes within the context" where "the context" means the entire system when -J is 0 or omitted altogether, and otherwise "the context" means the jail(s) specified by -J. It's slightly ironic that despite the apparent conflict, -J implies -a:

Code:
# alias count
alias count='awk '\''{print $1}'\'' | sort | uniq -c'

On the physical host, without -a, I see only processes owned by root. Adding -a shows all processes:

Code:
# ps -ux | count
   1 USER
  99 root
# ps -aux | count
   1 USER
   1 _dhcp
   1 bind
  80 jim
   1 messagebus
   1 ntpd
   1 polkitd
  99 root
   3 smmsp
   1 snmpd
  37 www

But when adding -Jx I now see all users processes in that jail, not just root's:

Code:
# ps -J12 -ux | count
   1 USER
   3 root
  25 www
# ps -J13,14 -ux | count
   1 USER
  12 root
   2 smmsp
   5 www

Indeed, when I specifically cite a username with -U, ps still shows me all users' processes:

Code:
# ps -J12 -ux -U root | count
   1 USER
  94 root
  25 www
# ps -J13,14 -ux -U root | count
   1 USER
  94 root
   2 smmsp
   5 www

Even more puzzling is:

Code:
# ps -ux -U www | wc -l
      38
# ps -J12 -ux -U www | wc -l
      41

Taken literally, that would mean that there are more www-owned processes in jail 12 alone, than there are in the entire system! I'll wager that, like -a, -U also activates -a.

Even -J0 mucks things up:

Code:
# ps -ux -Uwww | count
   1 USER
  37 www
# ps -J0 -ux -Uwww | count
   1 USER
   1 _dhcp
   1 bind
  80 jim
   1 messagebus
   1 ntpd
   1 polkitd
  84 root
   1 smmsp
   1 snmpd
  37 www

It may be time to formulate a pull request.

Thoughts?
 
Back
Top