Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)?

share|improve this question
For what purposes? – grawity Aug 17 '11 at 19:50
@gawity - specifically in follow-up to my previous question, but for reporting/monitoring purposes as well – warren Aug 17 '11 at 19:58
up vote 2 down vote accepted

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.

share|improve this answer
+1. The OP's question sounds like the traveling salesman problem. . . – surfasb Aug 18 '11 at 5:53
@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 Aug 18 '11 at 15:02
@warren: Nobody is knocking on the question. It is just we are pessimistic that there is a viable solution. – surfasb Aug 18 '11 at 23:20
@surfasb - understood completely ... just hoping there is some form of answer other than "you can't" or "you effectively can't" – warren Aug 19 '11 at 14:30

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
share|improve this answer
running tail -f /var/log/<product>/stderr.log & will have a tty associated as well, but is non-interactive :-| – warren Aug 17 '11 at 21:04
@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 Aug 17 '11 at 21:42
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 Aug 17 '11 at 22:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .