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 check its parent task ID, using `getppid()`
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.