Command Line

When an operating systems starts, one process (program) is started that then starts everything else as child processes.

'pstree' is a program that shows the hierarchy of processes that have started other processes (that are still running).

When a process starts a child process it is often referred to as spawning the process. And if a process automatically restarts if it crashes, it is referred to as respawning.

The main purpose of a program is to read and manipulate input and produce output. Input may be received when the program starts, or may be received during program execution by using system libraries that interact with operating system facilities such as a window server or networking. Output may be written to standard out, or may be communicated using other operating system faciltities such as disk or the network. A program will also return a integer status code - generally 0 for success, otherwise another value.

A key thing to differentiate is standard input and output mechanisms avaiable to a process, versus those that are made available via system libraries.

Standard input and output mechanisms

The following is standard due to both the pervasiveness of the C language runtime environment, and the POSIX standards for interoperable computing.

When a process starts it receives a copy of that portion of its parent's environment that has been exported to it.

When executed, programs:

In C, standard IO function declarations are accessed by including 'stdio.h'. i.e. provides 'getchar' and 'putchar' (or printf), etc.

The environment that a program is running in (e.g. when executed from a bash shell), may redirect the standard IO streams to files or other facilities.

$ my_program "first argument" "second argument" "third argument" <  input.txt > output.txt
$ echo $?
0
int main( int argc, char** argv )
{
    for ( int i=0; i < arc; i++ )
    {
        print_parameter( argv[i] );
    }
    return 0;
}
void print_parameter( char** parameter )
{
    printf( "%s\n", parameter );
}
output.txt
my_program
first argument
second argument
third argument

A program when it executes can be represented by a hierarchy of function calls that is referred to as the call-graph.