c++ - Determine whether a program is a GUI or console application in Linux -


i programming in c++ using qt-4 framework, given directory (i.e. /usr/bin) know whether program gui or console application.

i came across information on how windows , inexistence of similar (to win) identification on linux (within elf). there alternative way perform on linux?

i thought on:

  • spawning each entry qprocess , monitor it's lifetime assuming console application require input , did not provide any, print stoud message , exit. if it's alive after x-seconds, kill process , tag containing gui. horrible approach , error-prone;
  • run ldd , parse output libx or else. seems better approach although firefox, example, fail tagged having gui.

edit0: project app launcher

edit1: once have list of programs categorized, launch terminal emulator whenever user chooses non-graphical application

final conclusion:

after people answers , search, not possible reliably discern between console , gui applications. best bet make several considerations search .desktop files, make few assumptions tools listed in utilities-only places /bin, /sbin , /usr/sbin , on.

perhaps parse output of ldd each entry found.

thanks.

a program try start gui program, , else switch console. (and programs exhibit such behavior, e.g. emacs). @ random, or because of specific configuration...

for example, assuming vi console program , emacs graphical one, following simple program may randomly gui or console:

 #include <unistd.h>   int main(int argc, char**argv) {     if (getpid()%2 == 0)       { argv[0]="vi"; execv("/usr/bin/vi", argv); }     else       { argv[0]="emacs"; execv("/usr/bin/emacs", argv); }     return exit_failure;  } 

the simplest (but not foolproof) way of doing testing if getenv("display") returns null. more elaborate way call xopendisplay returns null on failure (and several x11 toolkits that).

so, question not have precise answer, , not make sense.

you use ldd .... , add manually exceptions firefox.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -