Разный вывод "ps -a" на Ubuntu и Fedora

516
obo

Я заметил, что ps -aкоманда выдает разные результаты, когда я запускаю ее на Ubuntu "16.04" и Fedora 23. В соответствии с man-страницей обоих дистрибутивов опция -a должна делать:

-a Выбрать все процессы, кроме обоих лидеров сеансов (см. getsid (2)) и процессов, не связанных с терминалом.

Это не похоже на случай с Ubuntu.

Я не могу объяснить это поведение, так как кажется, что они имеют одинаковую версию procps.

Fedora:

  • Название: procps-ng
  • версия: 3.3.10

Ubuntu:

  • Пакет: procps
  • Версия: 2: 3.3.10-4ubuntu2

Ты хоть представляешь, почему это происходит? Я делаю что-то неправильно ?

Спасибо, БР,

3

2 ответа на вопрос

2
Argonauts

There are, at least, two things this could be. The most likely is that ps is aliased to ps -A (or ps a; the a without the - results in behavior similar to -A) on fedora; which would explain the output format. On each system type which ps which will reveal what aliases if any are being called instead of the executable directly.

You can bypass any aliases by either either calling the full path of the program (e.g. /bin/ps or by starting the command with a leading '\', e.g. \ps.

The far less likely thing is that the two distros compiled ps with different flags (resulting in different behavior). I just checked ps on fedora 23, and it's default output is the same as what you are getting from ubunutu, so I think you have an alias set.

The alias is most likely set in the file ~/.bashrc; although other locations are possible. You can see the aliases in your current environment by typing alias with no arguments in the terminal.

Update:

Since they aren't aliased, something else (to state the obvious) is modifying the behavior. Here are a few things to look at to find out what that is: On each system, run them in a 'clean' environment:

env -i ps 

and see if the behavior changes. If it does, then we know it's an enviromental setting changing it.

on each system, enter the following command: ps --info

See if the field personality=0x field is non zero which can change the output. Note any other differences from that output; post them if you can't decode the meaning of the difference.

To see if something is re-purposing ps, run the following in the bash shell on each:

set -x ps -a 

You should see something like:

+ps -a 

echoed out; if you see something else, e.g. +ps aux, then that would cause this. That is usually done by an alias but it could be a function. You can turn off the bash spam by running set +x

On each machine check if the binary is an symlink to something else and if there is something odd going on there (likely on fedora that /usr/bin/ps is a sym link to /bin/ps)

ls -alt /bin/ps ls -alt /usr/bin/ps 

Try

type ps 

On each machine; the results should be the same, if not respond with the results.

There are some enviromental variables that can modify the behavior of ps; to see these type man ps; they are at the bottom. type env on each OS and see if any are set; you can grep for them:

env | grep 'CMD_ENV\|PS_PERSONALITY\|_XPG' 

There are others; see the manpage to add them to the query if these return nothing or to figure what the setting means to ps.

Getting into the weeds here, but if you still have nothing, check the binary file headers on each:

readelf -h /bin/ps 

If none of that shows any differences, you can copy the /bin/ps file to the other OS and do a compare:

cmp -b /bin/ps /path/to/copy/of/ps 

That will output all of the bytes that differ between the two files. The actual values don't matter; just the number of differences.

They will be different; if it's only a couple bytes difference than that would just be the gcc field NT_GNU_BUILD_ID which is unique for every build, even otherwise identical files. If they are not substantially different than it's an environmentally influenced behavior, and I can't think of anymore to check.

В обоих дистрибутивах псевдоним ps отсутствует, \ ps дает одинаковый результат. obo 7 лет назад 0
и команда `Какие PS` дал вам одинаковые результаты на обоих? Я обновил ответ с некоторыми дополнительными вещами, чтобы посмотреть. Argonauts 7 лет назад 0
Вывод «which ps» - это «/ usr / bin / ps» для fedora и «/ bin / ps» для ubuntu. У меня также есть grep вывод команды "alias", а "ps" нет. obo 7 лет назад 0
Версия Fedora `ps` велась как версия Ubuntu при запуске на Ubuntu. Может ли это быть связано с версией ядра (4.4.0 в Ubuntu и 4.4.9 в Fedora)? obo 7 лет назад 0
Вы пробовали другие шаги? env -i? Каковы были эти результаты? Argonauts 7 лет назад 0
Да, все остальные шаги не изменили поведение ps (кроме cmp, который я не тестировал) obo 7 лет назад 0
Исходя из того, что вы описали, это должна быть конфигурация среды. Я думаю, что один из тех тестов, которые я перечислил, будет указывать или, по крайней мере, намекает на один из них. Вероятность того, что ps --info даст одинаковые результаты, чрезвычайно низка, с другой системой сборки дистрибутивов. Какая версия убунту? Argonauts 7 лет назад 0
Я использую Ubuntu 16.04. ps --info не то же самое, gcc, glibc и ядро ​​разные obo 7 лет назад 0
Спасибо за вашу помощь. Я узнал кое-что из твоего ответа. obo 7 лет назад 0
0
obo

ps man page

-a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.

This behavior is explained by the fact that there is more processes attached to a terminal in Fedora compared to Ubuntu.

  1. Ubuntu
  2. Fedora