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)`
In short: you can't doing it directly.  

In long: look you can check the `getppid()` value and compare it with the `bash` PID or`b.out` PID  

TO search for a process inside the process table with Known PID with C you can do this: 

1) get the `PPID` of `a.out` and search with this value in `/porc` and then if you find the folder check the `cmdline` file and check if this process is `b.out` or `shell` process. 

2) you can deal with `sysctl` system call and dealing with kernel param's(you can google it) 

3)  

`pid_t ppid = getppid();  

 system("pidof bash > text.in");`

the `system` will get the pid of any shell process and write the result to `text.in` file  

it contains all bash PID's space separated you can compare this values with `getppid()` value.  

Good Luck.