Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get whole command line on AIX platform #1276

Closed
slqt opened this issue May 9, 2018 · 6 comments · Fixed by #1500
Closed

can't get whole command line on AIX platform #1276

slqt opened this issue May 9, 2018 · 6 comments · Fixed by #1500

Comments

@slqt
Copy link

slqt commented May 9, 2018

It may have error on all aix system,I guess.I run was and want get was's commad line on AIX 6.1 system,but I only can get little infomation of the whole command line .You can test the program with code below,11534558 is the process's pid :
`import psutil

proc=psutil.Process(11534558)

pidDictionary = proc.as_dict(attrs=['cmdline'])

print pidDictionary
`

@wiggin15
Copy link
Collaborator

wiggin15 commented May 9, 2018

I'm not sure I understand the problem correctly, but there is a known issue in AIX (and Solaris) that causes very long arguments in the command line to be "skipped" from Process.cmdline. See, for example, bullet 2 in this comment: #605 (comment).
and it's actually a test that is being skipped (https://github.com/giampaolo/psutil/blob/master/psutil/tests/test_process.py#L725).

If you run "ps", does it show the command line as you expect?

@slqt
Copy link
Author

slqt commented May 10, 2018

Thank you for the answer.
I can get the correct respond with the command 'ps -ef' on AIX,but can't with the command 'ps aux','ps -a' and 'ps'.Maybe you can use 'ps -ef' instead to get the whole process info.
I don't know why.I faced this problem when I use python to run and test the WebSphere's process on AIX,because was's pocess is very long.

@sandrotosi
Copy link

I have the same issue: the output from Process.cmdline() on AIX seems to be a list, split by spaces, of an 80-char string (try to len(' '.join(p.cmdline()), i get 79 when it's on a truncated cmdline process).

i can read the full command-line while running ps -edaf

@wiggin15
Copy link
Collaborator

There are two problems with long command lines on AIX:

  • Very long arguments are truncated and apparently cannot be retrieved, not with ps or any other method. They seem to be replaced with the previous argument instead. For example:
~ python -c "import time; time.sleep(1000)" &                                                                                                                                                  19-04-16 12:06
[1] 12059122
~ ps aux | grep python                                                                                                                                                                         19-04-16 12:06
root     12059122  0.0  0.0 1948 2012  pts/0 A    12:06:12  0:00 python -c -c
~ ps -edaf | grep python                                                                                                                                                                       19-04-16 12:06
    root 12059122  9044312   0 12:06:12  pts/0  0:00 python -c -c

In this case the argument import time; time.sleep(1000) is replaced with -c for some reason, and I can't find a way to get it.

  • A very long line is truncated in psutil and ps aux but not truncated by ps -ef:
~ python -c "import time; time.sleep(1000)" -c aaaaa  -c aaaaa  -c aaaaa  -c aaaaa -c aaaaa  -c aaaaa  -c aaaaa  -c aaaaa &                                                                    19-04-16 12:08
[1] 12059126
~ ps aux | grep python                                                                                                                                                                         19-04-16 12:08
root     12059126  0.0  0.0 1948 2012  pts/0 A    12:08:45  0:00 python -c -c -
~ ps -ef | grep python                                                                                                                                                                         19-04-16 12:08
    root 12059126  9044312   0 12:08:45  pts/0  0:00 python -c -c -c aaaaa -c aaaaa -c aaaaa -c aaaaa -c aaaaa -c aaaaa -c aaaaa -c aaaaa

ps -ef will truncate the same long parameter, but not the rest of the long line.

The latter case can be fixed in psutil by using getargs. Here is an example of how to use it:

void print_pid_args(int pid)
{
    char buf[8192];
    struct procsinfo procbuf;
    char *p = buf;
    procbuf.pi_pid = pid;

    getargs(&procbuf, sizeof(struct procinfo), buf,sizeof(buf));
    while (*p != '\0') {
        printf("%s ", p);
        p = strchr(p, '\0') + 1;
    }
}

@giampaolo
Copy link
Owner

It looks like getargs is a win indeed and it probably should be used instead of reading /proc/pid/psinfo:

psutil/psutil/_psutil_aix.c

Lines 151 to 158 in 7a3037e

sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
py_name = PyUnicode_DecodeFSDefault(info.pr_fname);
if (!py_name)
goto error;
py_args = PyUnicode_DecodeFSDefault(info.pr_psargs);

From:
https://sites.ualberta.ca/dept/chemeng/AIX-43/share/man/info/C/a_doc_lib/libs/basetrf1/getargs.htm
...looks like EBADF should be used as an alias for NoSuchProcess. Not sure what happens in case of permission error (I would expect something like EACCES but it's not mentioned in the man page).

@wiggin15
Copy link
Collaborator

Actually this is the correct documentation page for getargs:
https://www.ibm.com/support/knowledgecenter/ru/ssw_aix_72/com.ibm.aix.basetrf1/getargs.htm
errno will be ESRCH if the process is not found.

wiggin15 pushed a commit to Infinidat/psutil that referenced this issue Apr 30, 2019
wiggin15 pushed a commit to Infinidat/psutil that referenced this issue May 1, 2019
wiggin15 pushed a commit to Infinidat/psutil that referenced this issue May 1, 2019
nlevitt added a commit to nlevitt/psutil that referenced this issue May 6, 2019
* origin/master:
  Fix giampaolo#1276: [AIX] use getargs to get process cmdline (giampaolo#1500) (patch by @wiggin15)
  Fix Process.ionice example using wrong keyword arg (giampaolo#1504)
  fix history syntax
  remove catching IOError; let the test fail and adjust it later
  Fix cpu freq (giampaolo#1496)
  pre release
  fix giampaolo#1493: [Linux] cpu_freq(): handle the case where /sys/devices/system/cpu/cpufreq/ exists but is empty.
  Revert "Fix cpu_freq (giampaolo#1493)" (giampaolo#1495)
  Fix cpu_freq (giampaolo#1493)
  Update cpu_freq to return 0 for max/min if not available (giampaolo#1487)
  give CREDITS to @agnewee for giampaolo#1491
  SunOS / net_if_addrs(): free() ifap struct on error (giampaolo#1491)
  fix giampaolo#1486: add wraps() decorator around wrap_exceptions
  refactor/move some utilities into _common.py
  update doc
  update HISTORY
  Implement getloadavg on Windows. Fixes giampaolo#604 and giampaolo#1484 (giampaolo#1485) (patch by Ammar Askar)
  give credits to @amanusk for giampaolo#1472
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants