Complete procedure on how to use "gcov" code coverage tool in linux

#############################
How to test gcov in linux
#############################

##############################################################Step 1: Compile an image with the below flags and make sure that the process runs infinitely.##############################################################

gcc -Wall -fprofile-arcs -ftest-coverage hello.c -o hello

################################################################Step 2: Get the PID of the process that is running "infinitely" ################################################################

Neelkanth_221$ ps -elf | grep hello
0 R labuser  21036  5897 99  80   0 -  1056 -      20:53 pts/14   00:02:18 ./hello
0 S labuser  21047 20631  0  80   0 -  3989 pipe_w 20:56 pts/16   00:00:00 grep --color=auto hello

####################################################################
Step 3: Issue SIGUSR1 signal to the "pid" of the process for which
we will be running gcov.
####################################################################

kill -SIGUSR1 21055


####################################################################Step 4: hello.gcno file would be generated. do gcov <hello.gcno> to get the gcov report ####################################################################

hello.gcno
Neelkanth_221$ gcov hello.gcno
File 'hello.c'
Lines executed:93.33% of 15
Creating 'hello.c.gcov'


#####################################################################                  Sample "hello.c" code for gcov#####################################################################

/*
 * dumping gcov data at runtime - note: no error handling to keep it simple
 */
/*
 * Compile: gcc -Wall -fprofile-arcs -ftest-coverage hello.c -o hello
 * Run: ./hello &
 *      kill -s SIGUSR1 `pidof hello`
 *
 */
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

static unsigned long long i = 0;
void __gcov_flush(void); /* check in gcc sources gcc/gcov-io.h for the prototype */

void my_handler(int signum)
{
    printf("received signal\n");
    printf("%llu\n", i);
    __gcov_flush(); /* dump coverage data on receiving SIGUSR1 */
}

int main(int argc, char **argv)
{
    struct sigaction new_action, old_action;
    int n;

    /* setup signal hander */
    new_action.sa_handler = my_handler;
    sigemptyset(&new_action.sa_mask);
    new_action.sa_flags = 0;

    sigaction(SIGUSR1, NULL, &old_action);
    if (old_action.sa_handler != SIG_IGN)
        sigaction (SIGUSR1, &new_action, NULL);

    /* infinite loop - to exemplify dumping coverage data while program runs */
    for(n = 0; ; n++) {
        i++;

        if (0) {
            printf("roger federer\n");
        }
        if (0) {
            printf("roger federer\n");
        }
        if (0) {
            printf("roger federer\n");
        }
        if (0) {
            printf("roger federer\n");
        }
        if (0) {
            printf("roger federer\n");
        }

    }

}