Determine whether the parent process is a terminal

msrd0

I have a C++ program and I want to determine whether the parent process is a terminal or not. Because if it is a terminal, I can use escape codes to highlight the output, else this will be displayed with unreadable characters. The solution need to run on any posix system.

If anyone knows the solution for Java I would be interested in it as well.

user3553031

If I understand your problem correctly, you're looking at it from the wrong angle. Ask not what your parent process is, but rather what the capabilities of stdout are. And to do that in a POSIX environment, use isatty().

For stdout, isatty(STDOUT_FILENO) should return 1.

In Java, System.console() will apparently return a Console object if both stdin and stdout are a terminal, and null otherwise. See How can I check if a Java program's input/output streams are connected to a terminal? for more details.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to determine whether a process handle is of the current process?

From Dev

Bash: How to determine whether terminal is opened by third-party app

From Dev

How does the fork() know whether it is in child process and in parent process?

From Dev

Make terminal print name of parent process OSX

From Dev

How to determine whether a process's privilege exists and its enabled/disabled?

From Dev

Determine at runtime whether the "Visual Studio Hosting Process" is enabled?

From Dev

closing parent process(terminal) doesn't close a specific child process

From Dev

Checking the bash process in Terminal 1 is the parent process of a child process, FROM terminal 2?

From Dev

How can I determine if a process is running unseen in terminal?

From Dev

How to determine if a cp process in terminal (command line) is stuck?

From Dev

How do I determine if a process on Windows "has no parent"?

From Dev

Orphan process's parent id is not 1 when parent process executed from GNOME Terminal

From Dev

How to determine whether a div with some class is the last element of that class in a parent div - jQuery?

From Dev

Do you still need to check the parent / child pipelines to determine whether to create ICrmService or CrmService in 2015?

From Dev

How to determine whether a process is running or not and make use it to make a conditional shell script?

From Dev

Determine whether matrix is sparse?

From Dev

Determine whether a list is antisymmetric

From Dev

Determine whether assembly is a gui application

From Dev

Determine whether argument is a class or a protocol

From Java

Determine whether an array contains a value

From Dev

SlickGrid: determine whether row is selected

From Dev

Function to determine whether 2 numbers are =, > or <

From Dev

Determine whether or not execvp succeeded or failed

From Dev

Determine if an Ad displayed and whether it was clicked

From Dev

Determine whether argument is a class or a protocol

From Dev

Determine whether Powerpoint is in Presentation mode or not

From Dev

SlickGrid: determine whether row is selected

From Dev

Determine whether assembly is a gui application

From Dev

Determine whether scroll to bottom in div

Related Related

  1. 1

    How to determine whether a process handle is of the current process?

  2. 2

    Bash: How to determine whether terminal is opened by third-party app

  3. 3

    How does the fork() know whether it is in child process and in parent process?

  4. 4

    Make terminal print name of parent process OSX

  5. 5

    How to determine whether a process's privilege exists and its enabled/disabled?

  6. 6

    Determine at runtime whether the "Visual Studio Hosting Process" is enabled?

  7. 7

    closing parent process(terminal) doesn't close a specific child process

  8. 8

    Checking the bash process in Terminal 1 is the parent process of a child process, FROM terminal 2?

  9. 9

    How can I determine if a process is running unseen in terminal?

  10. 10

    How to determine if a cp process in terminal (command line) is stuck?

  11. 11

    How do I determine if a process on Windows "has no parent"?

  12. 12

    Orphan process's parent id is not 1 when parent process executed from GNOME Terminal

  13. 13

    How to determine whether a div with some class is the last element of that class in a parent div - jQuery?

  14. 14

    Do you still need to check the parent / child pipelines to determine whether to create ICrmService or CrmService in 2015?

  15. 15

    How to determine whether a process is running or not and make use it to make a conditional shell script?

  16. 16

    Determine whether matrix is sparse?

  17. 17

    Determine whether a list is antisymmetric

  18. 18

    Determine whether assembly is a gui application

  19. 19

    Determine whether argument is a class or a protocol

  20. 20

    Determine whether an array contains a value

  21. 21

    SlickGrid: determine whether row is selected

  22. 22

    Function to determine whether 2 numbers are =, > or <

  23. 23

    Determine whether or not execvp succeeded or failed

  24. 24

    Determine if an Ad displayed and whether it was clicked

  25. 25

    Determine whether argument is a class or a protocol

  26. 26

    Determine whether Powerpoint is in Presentation mode or not

  27. 27

    SlickGrid: determine whether row is selected

  28. 28

    Determine whether assembly is a gui application

  29. 29

    Determine whether scroll to bottom in div

HotTag

Archive