Process existence or/and permission

Hi,

In a bash script, I'm using kill -0 to test if I have permission to kill a process. There are 3 cases:

  • the process exists and I have permission: OK
  • the process doesn't exist and it's OK (because I decided to ignore processes that are already dead).
  • I don't have permission and I want to raise an error.

If I use ps $pid , I cannot tell the difference between a process that does not exist and a process I cannot "see":

santiago@alphard:~$ ps 1 > /dev/null && echo OK || echo ERR
ERR
santiago@alphard:~$ sudo ps 1 > /dev/null && echo OK || echo ERR
OK

If I use kill -0 $pid , I could tell the difference reading stderr but it would be language specific:

santiago@alphard:~$ for pid in 1 123; do for lc in C fr_FR.utf-8; do LC_ALL=$lc; kill -0 $pid; echo Status is $?; done; done
-su: kill: (1) - Operation not permitted
Status is 1
-su: kill: (1) - Opération non permise
Status is 1
-su: kill: (123) - No such process
Status is 1
-su: kill: (123) - Aucun processus de ce type
Status is 1

Question: How can I programmatically tell if a process exists and if I have permission on it?

Regards
Santiago

If you only worry about the language, you could use something like

LC_ALL=C kill -0 $pid

(or: LC_ALL=EN_en.utf-8 kill .....)

i.e. change the language to a well-defined value just for the scope of this command, and get the output always in English.

You can test with ps

if { ps -p $pid && ! kill -0 $pid; } >/dev/null 2>&1 ; then echo $pid is not killable; else echo happy; fi

Or

if { ! ps -p $pid || kill -0 $pid; } >/dev/null 2>&1 ; then echo happy; else echo $pid is not killable; fi

Thanks rovf,
That would mostly work I think but beside the language barrier, I don't like relying on error messages that could vary from one implementation to another. But that's the best answer so far.

Thanks MadeInGermany,
My problem is that on some systems, there are some processes that I just don't see as a normal user (not only no permission, really don't see) so I cannot rely on ps . Take the following example:

santiago@alphard:~$ ps 1; echo $?
  PID TTY      STAT   TIME COMMAND
1

It looks like process 1 does not exists but kill and sudo prove otherwise:

santiago@alphard:~$ kill -0 1
-bash: kill: (1) - Operation not permitted
santiago@alphard:~$ sudo ps 1; echo $?
  PID TTY      STAT   TIME COMMAND
    1 ?        Ss     2:55 init [2]
0

What OS has such a broken ps?

santiago@alphard:~$ uname -srv
Linux 3.14.32-xxxx-grs-ipv6-64 #9 SMP Thu Oct 20 14:53:52 CEST 2016
santiago@alphard:~$ cat /etc/debian_version
7.11
santiago@alphard:~$ bash --version | head -1
GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)
santiago@alphard:~$ ps --version
procps-ng version 3.3.3

I have many Debian and they all work fine except 2 of them. It is kernel related I think.

Here is a list of some of the kernels working fine (they are all Debian distribution kernels):

  • 2.06.26-2-686
  • 2.06.32-5-686
  • 2.06.32-5-amd64
  • 3.02.00-4-686-pae
  • 3.02.00-4-amd64
  • 3.16.00-4-amd64

Here are the 2 kernels that do NOT work as I wish (they are OVH Dedicated Server Debian custom kernel):

  • 2.06.21.05-grsec-xxxx-grs-ipv4-32
  • 3.14.32-xxxx-grs-ipv6-64

Unfortunately, I failed to upgrade the kernel because (according to the hosting company), the hardware is incompatible.

I can live with a non standard kernel but if anyone knows where I can tweak the setting that makes other users processes invisible, I'd take some help with great gratitude.

Regards
Santiago

If /proc/<pid>/ is unreadable then it's a kernel thing.

Indeed, all I see in /proc are my own processes:

santiago@alphard:~$ ls -ld /proc/{0..9}* 2> /dev/null
dr-xr-x--- 7 santiago root 0 Jun 28 14:05 /proc/13449
dr-xr-x--- 7 santiago root 0 Jun 28 14:05 /proc/13450
santiago@alphard:~$
santiago@alphard:~$ sudo -u www-data bash -c 'ls -ld /proc/{0..9}* 2> /dev/null'
dr-xr-x--- 7 www-data root 0 Jun 28 14:01 /proc/13112
dr-xr-x--- 7 www-data root 0 Jun 28 14:02 /proc/13178
dr-xr-x--- 7 www-data root 0 Jun 28 14:04 /proc/13331
dr-xr-x--- 7 www-data root 0 Jun 28 14:06 /proc/13459
dr-xr-x--- 7 www-data root 0 Jun 28 14:06 /proc/13469
dr-xr-x--- 7 www-data root 0 Jun 28 14:08 /proc/13582
dr-xr-x--- 7 www-data root 0 Jun 28 14:08 /proc/13584
dr-xr-x--- 7 www-data root 0 Jun 28 14:08 /proc/13586
dr-xr-x--- 7 www-data root 0 Jun 28 14:09 /proc/13634
dr-xr-x--- 7 www-data root 0 Jun 28 14:09 /proc/13638
dr-xr-x--- 7 www-data root 0 Jun 28 14:09 /proc/13639
dr-xr-x--- 7 www-data root 0 Jun 28 14:09 /proc/13644

You suppress stderr. Does the ls -ld actually say "permission denied" for the others?
If yes then it can see them, and you can do

test -d /proc/<pid>

BTW ls -ld /proc/{0..9}* can generate non-existing stuff if a certain first digit is not present; ls -ld /proc/[0-9]* is appropriate here.

All I was hiding from stderr is the non-existing stuff you mentioned. I only wanted to show process directories (starting with a digit). This is the full content of my /proc . Sorry for the long listing. Just wanted you to "see" the problem:

santiago@alphard:~$ ls -l /proc/
total 0
dr-xr-x---  7 santiago root     0 Jun 29 11:02 7476
dr-xr-x---  7 santiago root     0 Jun 29 11:02 7477
dr-xr-x---  7 santiago root     0 Jun 29 11:02 7506
dr-xr-xr-x  2 root     root     0 Jun 29 11:02 acpi
-r--r--r--  1 root     root     0 Jun 29 11:02 buddyinfo
dr-xr-xr-x  4 root     root     0 Jun 29 11:02 bus
-r--r--r--  1 root     root     0 Jun 29 11:02 cgroups
-r--r--r--  1 root     root     0 Jun 29 11:02 cmdline
-r--------  1 root     root 22624 Jun 29 11:02 config.gz
-r--r--r--  1 root     root     0 Jun 29 11:02 consoles
-r--r--r--  1 root     root     0 Jun 29 11:02 cpuinfo
-r--r--r--  1 root     root     0 Jun 29 11:02 crypto
-r--r--r--  1 root     root     0 Jun 29 11:02 devices
-r--r--r--  1 root     root     0 Jun 29 11:02 diskstats
-r--r--r--  1 root     root     0 Jun 29 11:02 dma
-r--r--r--  1 root     root     0 Jun 29 11:02 drbd
dr-xr-xr-x  2 root     root     0 Jun 29 11:02 driver
-r--r--r--  1 root     root     0 Jun 29 11:02 execdomains
-r--r--r--  1 root     root     0 Jun 29 11:02 fb
-r--r--r--  1 root     root     0 Jun 29 11:02 filesystems
dr-xr-xr-x 12 root     root     0 Jun 29 11:02 fs
dr-xr-xr-x  4 root     root     0 Jun 29 11:02 ide
-r--r--r--  1 root     root     0 Jun 29 11:02 interrupts
-r--r--r--  1 root     root     0 Jun 29 11:02 iomem
-r--r--r--  1 root     root     0 Jun 29 11:02 ioports
dr-xr-xr-x  2 root     root     0 Jun 29 11:02 ipmi
dr-xr-xr-x 32 root     root     0 Jun 29 11:02 irq
-r--r--r--  1 root     root     0 Jun 29 11:02 kallsyms
-r--r--r--  1 root     root     0 Jun 29 11:02 key-users
-r--------  1 root     root     0 Nov 29  2016 kmsg
-r--r--r--  1 root     root     0 Jun 29 11:02 loadavg
-r--r--r--  1 root     root     0 Jun 29 11:02 locks
-r--r--r--  1 root     root     0 Nov 29  2016 mdstat
-r--r--r--  1 root     root     0 Jun 29 11:02 meminfo
-r--r--r--  1 root     root     0 Jun 29 11:02 misc
lrwxrwxrwx  1 root     root    11 Jun 29 11:02 mounts -> self/mounts
dr-xr-xr-x  2 root     root     0 Jun 29 11:02 mpt
-r--r--r--  1 root     root     0 Jun 29 11:02 mtd
-rw-r--r--  1 root     root     0 Jun 29 11:02 mtrr
lrwxrwxrwx  1 root     root     8 Jun 29 11:02 net -> self/net
-r--r--r--  1 root     root     0 Jun 29 11:02 pagetypeinfo
-r--r--r--  1 root     root     0 Jun 29 11:02 partitions
dr-xr-xr-x  3 root     root     0 Jun 29 11:02 scsi
lrwxrwxrwx  1 root     root     0 Nov 29  2016 self -> 7506
-r--------  1 root     root     0 Jun 29 11:02 slabinfo
-r--r--r--  1 root     root     0 Jun 29 11:02 softirqs
-r--r--r--  1 root     root     0 Jun 29 11:02 stat
-r--r--r--  1 root     root     0 Jun 29 11:02 swaps
dr-xr-xr-x  1 root     root     0 Apr 15 18:46 sys
--w-------  1 root     root     0 Jun 29 11:02 sysrq-trigger
dr-xr-xr-x  2 root     root     0 Jun 29 11:02 sysvipc
-r--r--r--  1 root     root     0 Jun 29 11:02 timer_list
dr-xr-xr-x  4 root     root     0 Jun 29 11:02 tty
-r--r--r--  1 root     root     0 Jun 29 11:02 uptime
-r--r--r--  1 root     root     0 Jun 29 11:02 version
-r--------  1 root     root     0 Jun 29 11:02 vmallocinfo
-r--r--r--  1 root     root     0 Jun 29 11:02 vmstat
-r--r--r--  1 root     root     0 Jun 29 11:02 zoneinfo

And with sudo :

santiago@alphard:~$ sudo ls -lv /proc/
total 0
dr-xr-x---  7 root     root     0 Apr 15 18:46 1
dr-xr-x---  7 root     root     0 Apr 15 18:46 2
dr-xr-x---  7 root     root     0 Apr 15 18:46 3
dr-xr-x---  7 root     root     0 Apr 15 18:46 5
dr-xr-x---  7 root     root     0 Apr 15 18:46 7
dr-xr-x---  7 root     root     0 Apr 15 18:46 8
dr-xr-x---  7 root     root     0 Apr 15 18:46 9
dr-xr-x---  7 root     root     0 Apr 15 18:46 10
dr-xr-x---  7 root     root     0 Apr 15 18:46 11
dr-xr-x---  7 root     root     0 Apr 15 18:46 13
dr-xr-x---  7 root     root     0 Apr 15 18:46 14
dr-xr-x---  7 root     root     0 Apr 15 18:46 15
dr-xr-x---  7 root     root     0 Apr 15 18:46 17
dr-xr-x---  7 root     root     0 Apr 15 18:46 18
dr-xr-x---  7 root     root     0 Apr 15 18:46 19
dr-xr-x---  7 root     root     0 Apr 15 18:46 21
dr-xr-x---  7 root     root     0 Apr 15 18:46 22
dr-xr-x---  7 root     root     0 Apr 15 18:46 23
dr-xr-x---  7 root     root     0 Apr 15 18:46 25
dr-xr-x---  7 root     root     0 Apr 15 18:46 26
dr-xr-x---  7 root     root     0 Apr 15 18:46 27
dr-xr-x---  7 root     root     0 Apr 15 18:46 29
dr-xr-x---  7 root     root     0 Apr 15 18:46 30
dr-xr-x---  7 root     root     0 Apr 15 18:46 31
dr-xr-x---  7 root     root     0 Apr 15 18:46 33
dr-xr-x---  7 root     root     0 Apr 15 18:46 34
dr-xr-x---  7 root     root     0 Apr 15 18:46 35
dr-xr-x---  7 root     root     0 Apr 15 18:46 37
dr-xr-x---  7 root     root     0 Apr 15 18:46 38
dr-xr-x---  7 root     root     0 Apr 15 18:46 39
dr-xr-x---  7 root     root     0 Apr 15 18:46 40
dr-xr-x---  7 root     root     0 Apr 15 18:46 41
dr-xr-x---  7 root     root     0 Apr 15 18:46 42
dr-xr-x---  7 root     root     0 Apr 15 18:46 43
dr-xr-x---  7 root     root     0 Apr 15 18:46 44
dr-xr-x---  7 root     root     0 Apr 15 18:46 45
dr-xr-x---  7 root     root     0 Apr 15 18:46 46
dr-xr-x---  7 root     root     0 Apr 15 18:46 47
dr-xr-x---  7 root     root     0 Apr 15 18:46 48
dr-xr-x---  7 root     root     0 Apr 15 18:46 49
dr-xr-x---  7 root     root     0 Apr 15 18:46 50
dr-xr-x---  7 root     root     0 Apr 15 18:46 51
dr-xr-x---  7 root     root     0 Apr 15 18:46 52
dr-xr-x---  7 root     root     0 Apr 15 18:46 53
dr-xr-x---  7 root     root     0 Apr 15 18:46 54
dr-xr-x---  7 root     root     0 Apr 15 18:46 130
dr-xr-x---  7 root     root     0 Apr 15 18:46 131
dr-xr-x---  7 root     root     0 Apr 15 18:46 132
dr-xr-x---  7 root     root     0 Apr 15 18:46 133
dr-xr-x---  7 root     root     0 Apr 15 18:46 134
dr-xr-x---  7 root     root     0 Apr 15 18:46 135
dr-xr-x---  7 root     root     0 Apr 15 18:46 136
dr-xr-x---  7 root     root     0 Apr 15 18:46 137
dr-xr-x---  7 root     root     0 Apr 15 18:46 138
dr-xr-x---  7 root     root     0 Apr 15 18:46 139
dr-xr-x---  7 root     root     0 Apr 15 18:46 140
dr-xr-x---  7 root     root     0 Apr 15 18:46 141
dr-xr-x---  7 root     root     0 Apr 15 18:46 142
dr-xr-x---  7 root     root     0 Apr 15 18:46 143
dr-xr-x---  7 root     root     0 Apr 15 18:46 144
dr-xr-x---  7 root     root     0 Apr 15 18:46 145
dr-xr-x---  7 root     root     0 Apr 15 18:46 146
dr-xr-x---  7 root     root     0 Apr 15 18:46 147
dr-xr-x---  7 root     root     0 Apr 15 18:46 148
dr-xr-x---  7 root     root     0 Apr 15 18:46 149
dr-xr-x---  7 root     root     0 Apr 15 18:46 150
dr-xr-x---  7 root     root     0 Apr 15 18:46 151
dr-xr-x---  7 root     root     0 Apr 15 18:46 182
dr-xr-x---  7 root     root     0 Apr 15 18:46 184
dr-xr-x---  7 root     root     0 Apr 15 18:46 187
dr-xr-x---  7 root     root     0 Apr 15 18:46 190
dr-xr-x---  7 root     root     0 Apr 15 18:46 191
dr-xr-x---  7 root     root     0 Apr 15 18:46 192
dr-xr-x---  7 root     root     0 Apr 15 18:46 193
dr-xr-x---  7 root     root     0 Apr 15 18:46 195
dr-xr-x---  7 root     root     0 Apr 15 18:46 196
dr-xr-x---  7 root     root     0 Apr 15 18:46 197
dr-xr-x---  7 root     root     0 Apr 15 18:46 198
dr-xr-x---  7 root     root     0 Apr 15 18:46 199
dr-xr-x---  7 root     root     0 Apr 15 18:46 200
dr-xr-x---  7 root     root     0 Apr 15 18:46 201
dr-xr-x---  7 root     root     0 Apr 15 18:46 202
dr-xr-x---  7 root     root     0 Apr 15 18:46 203
dr-xr-x---  7 root     root     0 Apr 15 18:46 204
dr-xr-x---  7 root     root     0 Apr 15 18:46 205
dr-xr-x---  7 root     root     0 Apr 15 18:46 206
dr-xr-x---  7 root     root     0 Apr 15 18:46 207
dr-xr-x---  7 root     root     0 Apr 15 18:46 213
dr-xr-x---  7 root     root     0 Apr 15 18:46 214
dr-xr-x---  7 root     root     0 Apr 15 18:46 215
dr-xr-x---  7 root     root     0 Apr 15 18:46 218
dr-xr-x---  7 root     root     0 Apr 15 18:46 219
dr-xr-x---  7 root     root     0 Apr 15 18:46 221
dr-xr-x---  7 root     root     0 Apr 15 18:46 222
dr-xr-x---  7 root     root     0 Apr 15 18:46 223
dr-xr-x---  7 root     root     0 Apr 15 18:46 224
dr-xr-x---  7 root     root     0 Apr 15 18:46 225
dr-xr-x---  7 root     root     0 Apr 15 18:46 226
dr-xr-x---  7 root     root     0 Apr 15 18:46 227
dr-xr-x---  7 root     root     0 Apr 15 18:46 228
dr-xr-x---  7 root     root     0 Apr 15 18:46 229
dr-xr-x---  7 root     root     0 Apr 15 18:46 230
dr-xr-x---  7 root     root     0 Apr 15 18:46 231
dr-xr-x---  7 root     root     0 Apr 15 18:46 232
dr-xr-x---  7 root     root     0 Apr 15 18:46 233
dr-xr-x---  7 root     root     0 Apr 15 18:46 234
dr-xr-x---  7 root     root     0 Apr 15 18:46 235
dr-xr-x---  7 root     root     0 Apr 15 18:46 236
dr-xr-x---  7 root     root     0 Apr 15 18:46 237
dr-xr-x---  7 root     root     0 Apr 15 18:46 238
dr-xr-x---  7 root     root     0 Apr 15 18:46 239
dr-xr-x---  7 root     root     0 Apr 15 18:46 240
dr-xr-x---  7 root     root     0 Apr 15 18:46 241
dr-xr-x---  7 root     root     0 Apr 15 18:46 242
dr-xr-x---  7 root     root     0 Apr 15 18:46 243
dr-xr-x---  7 root     root     0 Apr 15 18:46 244
dr-xr-x---  7 root     root     0 Apr 15 18:46 353
dr-xr-x---  7 root     root     0 Jun 12 17:01 505
dr-xr-x---  7 root     root     0 Apr 15 18:46 603
dr-xr-x---  7 root     root     0 Apr 15 18:46 776
dr-xr-x---  7 root     root     0 Apr 15 18:46 1731
dr-xr-x---  7 root     root     0 Apr 15 18:46 1732
dr-xr-x---  7 root     root     0 Apr 15 18:46 1788
dr-xr-x---  7 root     root     0 Apr 15 18:46 1789
dr-xr-x---  7 root     root     0 Apr 15 18:46 1798
dr-xr-x---  7 root     root     0 Apr 15 18:46 1799
dr-xr-x---  7 root     root     0 Apr 15 18:46 1822
dr-xr-x---  7 root     root     0 Apr 15 18:46 1823
dr-xr-x---  7 root     root     0 Apr 15 18:46 1825
dr-xr-x---  7 root     root     0 Apr 15 18:46 1826
dr-xr-x---  7 root     root     0 Apr 15 18:46 2344
dr-xr-x---  7 root     root     0 Apr 15 18:46 2418
dr-xr-x---  7 root     root     0 Apr 15 18:46 2588
dr-xr-x---  7 root     root     0 Apr 15 18:46 2596
dr-xr-x---  7 root     root     0 Apr 15 18:46 2597
dr-xr-x---  7 root     root     0 Apr 15 18:46 2598
dr-xr-x---  7 root     root     0 Apr 15 18:46 2599
dr-xr-x---  7 root     root     0 Apr 15 18:46 2600
dr-xr-x---  7 root     root     0 Apr 15 18:46 2601
dr-xr-x---  7 root     root     0 Apr 15 18:46 2605
dr-xr-x---  7 root     root     0 Apr 15 18:46 2606
dr-xr-x---  7 root     root     0 Apr 15 18:46 2607
dr-xr-x---  7 root     root     0 Jun 14 12:01 3204
dr-xr-x---  7 root     root     0 Apr 15 18:46 3654
dr-xr-x---  7 root     root     0 Apr 15 18:46 3861
dr-xr-x---  7 root     root     0 May 19 12:01 5595
dr-xr-x---  7 root     root     0 Jun 29 11:01 7351
dr-xr-x---  7 www-data root     0 Jun 29 11:01 7365
dr-xr-x---  7 root     root     0 Jun 29 11:02 7474
dr-xr-x---  7 santiago root     0 Jun 29 11:02 7476
dr-xr-x---  7 santiago root     0 Jun 29 11:02 7477
dr-xr-x---  7 www-data root     0 Jun 29 11:03 7562
dr-xr-x---  7 www-data root     0 Jun 29 11:04 7634
dr-xr-x---  7 www-data root     0 Jun 29 11:04 7635
dr-xr-x---  7 www-data root     0 Jun 29 11:06 7693
dr-xr-x---  7 www-data root     0 Jun 29 11:06 7695
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7748
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7751
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7755
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7756
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7759
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7760
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7764
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7765
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7768
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7769
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7771
dr-xr-x---  7 www-data root     0 Jun 29 11:07 7774
dr-xr-x---  7 root     root     0 Jun 29 11:07 7820
dr-xr-x---  7 santiago root     0 Jun 29 11:07 7821
dr-xr-x---  7 root     root     0 Jun 29 11:07 7822
dr-xr-x---  7 root     root     0 Apr 15 18:46 8996
dr-xr-x---  7 root     root     0 Apr 15 18:46 9130
dr-xr-x---  7 bind     root     0 Apr 15 18:46 9165
dr-xr-x---  7 ntp      root     0 Apr 15 18:46 10865
dr-xr-x---  7 postfix  root     0 Jun 29 09:37 11110
dr-xr-x---  7 root     root     0 Jun 14 17:00 11454
dr-xr-x---  7 root     root     0 May 27 03:01 11919
dr-xr-x---  7 root     root     0 May  7 05:01 12601
dr-xr-x---  7 root     root     0 Jun 18 03:01 12891
dr-xr-x---  7 root     root     0 May  7 02:01 13866
dr-xr-x---  7 root     root     0 Apr 15 18:46 14691
dr-xr-x---  7 postfix  root     0 Apr 15 18:46 17272
dr-xr-x---  7 root     root     0 Apr 15 18:46 24950
dr-xr-x---  7 postfix  root     0 Apr 15 18:46 24957
dr-xr-x---  7 root     root     0 Apr 15 18:46 26142
dr-xr-x---  7 root     root     0 Jun 29 08:16 26908
dr-xr-x---  7 root     root     0 Apr 15 18:46 30321
dr-xr-x---  7 root     root     0 Apr 15 18:46 30662
dr-xr-x---  7 root     root     0 Jun  4 04:01 30988
dr-xr-xr-x  2 root     root     0 Jun 29 11:07 acpi
-r--r--r--  1 root     root     0 Jun 29 11:07 buddyinfo
dr-xr-xr-x  4 root     root     0 Jun 29 11:07 bus
-r--r--r--  1 root     root     0 Jun 29 11:07 cgroups
-r--r--r--  1 root     root     0 Jun 29 11:07 cmdline
-r--------  1 root     root 22624 Jun 29 11:07 config.gz
-r--r--r--  1 root     root     0 Jun 29 11:07 consoles
-r--r--r--  1 root     root     0 Jun 29 11:07 cpuinfo
-r--r--r--  1 root     root     0 Jun 29 11:07 crypto
-r--r--r--  1 root     root     0 Jun 29 11:07 devices
-r--r--r--  1 root     root     0 Jun 29 11:07 diskstats
-r--r--r--  1 root     root     0 Jun 29 11:07 dma
-r--r--r--  1 root     root     0 Jun 29 11:07 drbd
dr-xr-xr-x  2 root     root     0 Jun 29 11:07 driver
-r--r--r--  1 root     root     0 Jun 29 11:07 execdomains
-r--r--r--  1 root     root     0 Jun 29 11:07 fb
-r--r--r--  1 root     root     0 Jun 29 11:07 filesystems
dr-xr-xr-x 12 root     root     0 Jun 29 11:07 fs
dr-xr-xr-x  4 root     root     0 Jun 29 11:07 ide
-r--r--r--  1 root     root     0 Jun 29 11:07 interrupts
-r--r--r--  1 root     root     0 Jun 29 11:07 iomem
-r--r--r--  1 root     root     0 Jun 29 11:07 ioports
dr-xr-xr-x  2 root     root     0 Jun 29 11:07 ipmi
dr-xr-xr-x 32 root     root     0 Jun 29 11:07 irq
-r--r--r--  1 root     root     0 Jun 29 11:07 kallsyms
-r--r--r--  1 root     root     0 Jun 29 11:07 key-users
-r--------  1 root     root     0 Nov 29  2016 kmsg
-r--r--r--  1 root     root     0 Jun 29 11:07 loadavg
-r--r--r--  1 root     root     0 Jun 29 11:07 locks
-r--r--r--  1 root     root     0 Nov 29  2016 mdstat
-r--r--r--  1 root     root     0 Jun 29 11:07 meminfo
-r--r--r--  1 root     root     0 Jun 29 11:07 misc
lrwxrwxrwx  1 root     root    11 Jun 29 11:07 mounts -> self/mounts
dr-xr-xr-x  2 root     root     0 Jun 29 11:07 mpt
-r--r--r--  1 root     root     0 Jun 29 11:07 mtd
-rw-r--r--  1 root     root     0 Jun 29 11:07 mtrr
lrwxrwxrwx  1 root     root     8 Jun 29 11:07 net -> self/net
-r--r--r--  1 root     root     0 Jun 29 11:07 pagetypeinfo
-r--r--r--  1 root     root     0 Jun 29 11:07 partitions
dr-xr-xr-x  3 root     root     0 Jun 29 11:07 scsi
lrwxrwxrwx  1 root     root     0 Nov 29  2016 self -> 7822
-r--------  1 root     root     0 Jun 29 11:07 slabinfo
-r--r--r--  1 root     root     0 Jun 29 11:07 softirqs
-r--r--r--  1 root     root     0 Jun 29 11:07 stat
-r--r--r--  1 root     root     0 Jun 29 11:07 swaps
dr-xr-xr-x  1 root     root     0 Apr 15 18:46 sys
--w-------  1 root     root     0 Jun 29 11:07 sysrq-trigger
dr-xr-xr-x  2 root     root     0 Jun 29 11:07 sysvipc
-r--r--r--  1 root     root     0 Jun 29 11:07 timer_list
dr-xr-xr-x  4 root     root     0 Jun 29 11:07 tty
-r--r--r--  1 root     root     0 Jun 29 11:07 uptime
-r--r--r--  1 root     root     0 Jun 29 11:07 version
-r--------  1 root     root     0 Jun 29 11:07 vmallocinfo
-r--r--r--  1 root     root     0 Jun 29 11:07 vmstat
-r--r--r--  1 root     root     0 Jun 29 11:07 zoneinfo

Ok, not present, no workaround.

Traditionally mount(-options) at boot is done in /etc/fstab - but newer Linux seem to mount /proc by magic.?

When I don't know how to undo something, I often search how to DO it. It worked today with linux hide processes from other users - Recherche Google.
So if hidepid allows you to hide processes, it should do the opposite if deactivated.
Apparently hidepid is not in use though and I can only see 4 processes wether I use ls /proc or ps :

santiago@alphard:~$ sudo mount | grep proc
proc on /proc type proc (rw,relatime)
santiago@alphard:~$ ls -ld /proc/{0..9}* 2> /dev/null | wc -l
4
santiago@alphard:~$ ps x -o pid= | wc -l
4

But I'm still going to try to tweak hidepid and indeed I can see more processes with ls /proc but not with ps :

santiago@alphard:~$ sudo mount -o remount,hidepid=1 /proc
santiago@alphard:~$ sudo mount | grep proc
proc on /proc type proc (rw,relatime,hidepid=1)
santiago@alphard:~$ ls -ld /proc/{0..9}* 2> /dev/null | wc -l
202
santiago@alphard:~$ ps x -o pid= | wc -l
4

Surprisingly, hidepid level 1 gives me more permission but levels 0 and 2 are exactly the same:

santiago@alphard:~$ (echo -e "mount opt\tls /proc\tps" | sed 'p;s/[^\t]/-/g'; for h in 0 1 2; do echo -e "hidepid=$h\t$(sudo mount -o remount,hidepid=$h /proc; ls -ld /proc/{0..9}* 2> /dev/null | wc -l)\t$(ps x -o pid= | wc -l)"; done) | column -tns$'\t'
mount opt  ls /proc  ps
---------  --------  --
hidepid=0  7         7
hidepid=1  201       7
hidepid=2  7         7

I'm still investigating but level 0 should give me all permissions like in old behavior.

To me this looks like the result of /proc having rather weird permissions. What does

ls -ld /proc

show? Because if it is flagged "0" (oct) for "others" you can't even see directory entries in there except for the ones you are directly permitted to (by their own permissions).

I just checked with a system running kernel "3.0.101-97-default" (according to uname , some old SLES, i believe) and the output was

# ls -ld /proc
dr-xr-xr-x 182 root root 0 Jun 27 20:03 /proc

So users are able to see the directory entries in there, even if they are not permitted to access them.

I hope this helps.

bakunin

Yes, default should be hidepid=0 and all processes readable.
You have a special kernel.
--
For my special interest:
does somebody happen to know how to set mount options if /proc is not in /etc/fstab??