Question: I have a simple C/CPP process running on a linux system. This is a.out.

Another process is capable to start a.out inside its code. This is b.out.

What code do I need inside a.out to understand that it is executed from the command line?
Eg ./a.out

Is there a way a process to know if it started from the cmd or started from another process?

Answer: 
You can do multiple things, but none will be 100% reliable:

* `isatty(0)` to check whether standard input is a TTY terminal,
* check for the parent task ID (`getppid()`), then lookup the parent's PID to match it against its executable's path (using whatever you want. a call to `ps` and some parsing could do, or have fun using `/proc/`)
* you could also just have a look at the environment variables set up. do a printout of all the values contained in the env. To do that, either use the extern `environ` variable:

`extern char **environ;`
* or modify your `main()` prototype to be:

`int main(int ac, char **av, char **environ)`
You can check whether its standard input is a terminal:

```
if(isatty(0)) { ... }

```