[info-softwarecounter.py] process ID out of range for gnome-builder
jfernandz opened this issue · 16 comments
I've noticed that I have an error message when I open gnome-builder which says error: process ID out of range, this is strange because according to /proc/sys/kernel/pid_max:
$ cat /proc/sys/kernel/pid_max
4194304
$ ps aux | grep "builder\|^U"
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
jfernan+ 420762 0.0 0.0 2424 672 ? S 16:58 0:00 bwrap --args 31 gnome-builder
jfernan+ 420770 0.0 0.0 2784 1544 ? S 16:58 0:00 bwrap --args 31 gnome-builder
jfernan+ 420771 6.3 1.1 102097972 158948 ? Sl 16:58 0:10 gnome-builder
jfernan+ 420855 0.3 0.1 149216 21844 ? Ssl 16:58 0:00 /app/libexec/gnome-builder-git
jfernan+ 420927 1.5 1.0 313940 154220 ? Ssl 16:58 0:02 /app/libexec/gnome-builder-clang
jfernan+ 422466 0.0 0.0 8916 2456 pts/1 S+ 17:00 0:00 grep builder\|^U
The process ID is in range, so could this be a problem with subprocess python module? I would like in fact to add gnome-builder to the vims tuple in the dict, but it has not any effect because of the error message. This is the traceback
error: process ID out of range
Usage:
ps [options]
Try 'ps --help <simple|list|output|threads|misc|all>'
or 'ps --help <s|l|o|t|m|a>'
for additional help text.
For more details see ps(1).
Traceback (most recent call last):
File "/home/jfernandez/dotfiles/polybar/.config/polybar/polybar-scripts/./info-softwarecounter.py", line 81, in <module>
gui_counts = Counter(get_running_guis())
File "/home/jfernandez/dotfiles/polybar/.config/polybar/polybar-scripts/./info-softwarecounter.py", line 74, in get_running_guis
validprocs = [
File "/home/jfernandez/dotfiles/polybar/.config/polybar/polybar-scripts/./info-softwarecounter.py", line 75, in <listcomp>
get_process(w[2]) for w in wlist if check_wtype(w[0]) == True
File "/home/jfernandez/dotfiles/polybar/.config/polybar/polybar-scripts/./info-softwarecounter.py", line 69, in get_process
proc = get(["ps", "-p", w_id, "-o", "comm="])
File "/home/jfernandez/dotfiles/polybar/.config/polybar/polybar-scripts/./info-softwarecounter.py", line 61, in <lambda>
get = lambda cmd: subprocess.check_output(cmd).decode("utf-8").strip()
File "/usr/lib/python3.9/subprocess.py", line 420, in check_output
return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
File "/usr/lib/python3.9/subprocess.py", line 524, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['ps', '-p', '0', '-o', 'comm=']' returned non-zero exit status 1.
Probably; I didn't diagnose that one, though, just stopped using conky.
Some idea to diagnose this time?
@jtambasco wrote the script. Maybe he has an idea and wants to answer.
Hi, unfortunately I don't use linux anymore due to work requirements. But I believe one limitation of the script is that you cannot combine GUIs with commandline programs. The counting part of the script would need to be modified to allow this, from line 119 in the script.
You can easily run the script independently of BSPWM using python and check what output you get, print various lines and modify it.
Also, from what you posted, subprocess.CalledProcessError: Command '['ps', '-p', '0', '-o', 'comm=']' returned non-zero exit status 1., I believe the script has somehow decided that the PID of gnome-builder is 0, which it's obviously not. It'll be some six-didgt number > 0. I believe this is, again, because the program is trying to treat a 'GUI' program as a 'process', which is not supported (but could be with some modification).
Perhaps try combining the gnome-builder GUI in one of the combine_guis sections, like 'filemanagers' and see if that works. If it does, then you definitely cannot combine GUIs with terminal programs without further script modifications. If it still fails when doing that, then there is probably something inconsistent with the naming of gnome-builder in the system process commands.
I'll try to work on this, thank you @jtambasco (you should use Linux in your private life, though 🤣 )
I've tried to add gnome-builder to the combine_guis sections but this didn't work, so I guess I have to look deeper in the script 🤔
Thank you anyway and if you have some idea I'll appreciate if you share it 😁
@jtambasco apparently the problem is wmctrl -lp shows a wrong PID for gnome-builder as you can see here:
$ wmctrl -lp
0x03800001 1 98302 jfthkpad (1) WhatsApp
0x02a00003 1 1480 jfthkpad
0x03000007 2 3854 jfthkpad Python Lambda - Google Chrome
0x04400008 1 4 jfthkpad #música - Discord
0x02c00006 1 650946 jfthkpad Telegram
0x03e00003 0 652030 jfthkpad
0x04200003 0 660088 jfthkpad
0x05000007 0 0 jfthkpad Builder — Open a Project
0x05200003 0 664011 jfthkpad
Why do you think is this for? 🤔
Yeh that's weird, it clearly doesn't match the other PID, and 0 is clearly not a realistic PID. No idea why wmctrl is giving that value.
Perhaps try this: Instead of putting the gnome-builder in the gui section, can you just put it in the process section, so it doesn't bother with the whole wmctrl?
@jtambasco the problem is the same wherever I put gnome-builder, the first time in fact I was trying by adding it to combine_processes dict (in the vims tuple) so I don't know what could be happening.
When I run pgrep -c -x gnome-builder the count is 1 so I guess this is fine, maybe that 0 in the wmctrl is a problem at all.
I was thinking in bypassing it with an if l > 0 in the line 72
But I'm still not sure why adding it to the processes section didn't work, where it uses pgrep instead. What is the error here?
It shouldn't call wmctrl I believe when addind it to the processes section.
@jtambasco the point is the error is also when gnome-builder is not even in the script, so ... that 0 could be a problem in any way.
Oh, okay. So if you set GUI=False on line 9, it works right?
Exactly. Could this has something to do with the fact that I've installed Gnome Builder with flatpak? 🤔
On line 75, does this work:
get_process(w[2]) for w in wlist if check_wtype(w[0]) == True and w[2] != '0'
And no idea why the PID is 0. However, we can just try tell the script to ignore PID that are 0, as you were kind of mentioning before :)
Do you want to do the fix? Should I do a PR? this looks a good workaround as well as good error correction mechanism.
I was thinking about the flatpak thing .. and I think it's strange because I've installed also Discord through flatpak and it has a strange PID (4 😕)
0x03800001 1 98302 jfthkpad WhatsApp
0x02a00003 1 1480 jfthkpad
0x03000007 2 3854 jfthkpad [info-softwarecounter.py] process ID out of range for gnome-builder · Issue #291 · polybar/polybar-scripts - Google Chrome
0x02c00006 1 650946 jfthkpad Telegram
0x03e00003 0 652030 jfthkpad
0x04400008 1 4 jfthkpad General - Discord
0x04200007 0 0 jfthkpad Builder — Open a Project
0x05000003 0 693479 jfthkpad
Maybe those PIDs are referred to the runtime sandboxes 🤔
Just to confirm, it worked with that code code change, right? I'll submit a PR in a sec.
Yeh, I noticed the PID 4 before, it does look suspicious. Maybe there is some PID linux documentation. Also, I guess I don't even need to use the PID in the code, maybe I should've just used the last column there... i.e. checked for "Builder - Open a Project" or "General - Discord". I guess the code could be improved.