Can the interactivity of a process be determined programmatically?

1

Is it possible to determine whether or not a given running process is interactive or merely daemon-like (i.e. an actual daemon, or a tail -f, or similar) using scripting or any other language?

If so, how?

Is it possible on more than one platform (I use bash most often, but solutions in other shells - even PowerShell - would be appreciated, too)?

warren

Posted 2011-08-17T19:43:49.997

Reputation: 8 599

For what purposes? – user1686 – 2011-08-17T19:50:49.797

@gawity - specifically in follow-up to my previous question, but for reporting/monitoring purposes as well

– warren – 2011-08-17T19:58:59.613

Answers

2

based on your comment to the other answer, what you're asking for is very hard.

You could check the libraries the app connects to, and if they're screen control (e.g. ncurses) it's probably interactive. Though these could run 'non-interactive (by your definition)' with certain run situations.

I think the best you could do is use strace, which would show you the syscalls the app uses. If it's reading from a fd that's attached to a tty, then it's interactive.

Rich Homolka

Posted 2011-08-17T19:43:49.997

Reputation: 27 121

+1. The OP's question sounds like the traveling salesman problem. . . – surfasb – 2011-08-18T05:53:38.387

@surfasb - it may be that what I'm looking for is extremely diffult / essentially impossible, but it's always worth a try to ask :) – warren – 2011-08-18T15:02:13.507

1@warren: Nobody is knocking on the question. It is just we are pessimistic that there is a viable solution. – surfasb – 2011-08-18T23:20:02.190

@surfasb - understood completely ... just hoping there is some form of answer other than "you can't" or "you effectively can't" – warren – 2011-08-19T14:30:29.837

0

If I understand your question correctly, an interactive process should have a tty associated with it.

The following on a Linux system should give you all the interactive processes:

ps -e | grep pts

OldWolf

Posted 2011-08-17T19:43:49.997

Reputation: 2 293

running tail -f /var/log/<product>/stderr.log & will have a tty associated as well, but is non-interactive :-| – warren – 2011-08-17T21:04:30.893

@warren That job is still technically interactive unless you nohup it and disconnect the controlling terminal. An admittedly sloppy analogy would be having two terminal sessions open and ignoring the running process in one of the terminals. The process is still interactive, you're just not paying any attention to it. What is the overall problem you're trying to solve? – OldWolf – 2011-08-17T21:42:22.193

tail is a non-interactive program: it merely displays contents of a file (or similar). I'm trying to determine via a script or other tool if a user is running something like emacs, vi, less, etc - rather than something like cat, tail, or head – warren – 2011-08-17T22:22:33.483