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't find out in general whether a program was started "from the command line" (by a user's explicit command), but you can find out whether its standard input and output are talking to a terminal/command window:

```
#include <unistd.h>
isatty(fileno(stdin))

```

and `stdout` return whether standard input/standard output are terminals.

If you need to know what process starting your program, use the [`getppid`](http://www.opengroup.org/onlinepubs/009695399/functions/getppid.html) system call to get the parent's process ID (ppid), then read the pseudo-file `/proc/`*ppid*`/cmdline`.
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.