I'm trying to know if some GUI process is idle o minimized in Linux, using Net-SNMP.

I've been doing research and as far as I know, SNMP seems to be designed for monitoring services, not processes run by regular users.

I've found just one MIB object, hrSWRunStatus (RFC 2790), which has only four running statuses: running(1), runnable(2), notRunnable(3) and invalid(4), but testing by maximizing and minimizing some GUI applications don't display any changes in their respective statuses, in fact, every process listed with snmpwalk has runnable(2) status, except one: snmpd which is listed as running(1).

# snmpwalk -v 2c -c public localhost . | grep "running(1)"
HOST-RESOURCES-MIB::hrSWRunStatus.920 = INTEGER: running(1)
# snmpwalk -v 2c -c public localhost . | grep 920
HOST-RESOURCES-MIB::hrSWRunName.920 = STRING: "snmpd"

Even using ps I don't see a change in the status of a process I'm using at the moment (except for htop). If htop is running in a terminal console, like konsole and I'm writing a text with kate, none of those processes has the status "R" (running or runnable), just "S" (interruptible sleep), which I found weird, but is supposed to be in that way... https://supportcenter.checkpoint.com/supportcenter/portal?eventSubmit_doGoviewsolutiondetails=&solutionid=sk112953

So, how can I know, in Linux, if some process is idle or minimized...?

  • 2
    Processes cannot be minimized, only windows can. There is no relationship between the status of a window and the status of a process. – AlexP Oct 12 at 0:13
  • @AlexP so, I've should ask "how can I know if some GUI software is minimized?"... is that possible? – abiyi Oct 12 at 0:16
  • 1
    Not with Net-SNMP. You would have to communicate with the window manager process of your desktop environment to get that information. (This sounds like an XY problem. What is the problem you're trying to solve by finding out if a GUI program is minimized or not?) – telcoM Oct 12 at 0:20
  • @telcoM I want to record the time used with some applications, if the app is minimized or in the background then it's not being used, if the app is the foreground and is active then is being used. Basically, I want to develop my own time tracking app, using open source tools on Linux. – abiyi Oct 12 at 0:34

In the comments you said you want to develop a time tracking app, for tracking application usage. I guess you might do it by tracking which window is the active one at any given time.

To do that, you would need to get access to the user's X11 session, and then repeatedly query its X11 property named _NET_ACTIVE_WINDOW.

This code example might be helpful to you: https://github.com/UltimateHackingKeyboard/current-window-linux/blob/master/get-current-window.c

If the system uses Wayland instead of classic X11, unfortunately Wayland might require its own solution; I simply don't know enough about that one.

  • looking for more info about the X11 _NET_ACTIVE_WINDOW property I got a couple of commands that manage X11 properties this post that answers my question: superuser.com/questions/382616/…, so I have two apps: xdotool (very simple to manage but doesn't manage all the X11 properties) and xprop (hard to understand but very robust, managing all the X11 properties), so I choose the last one. – abiyi Oct 17 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.