Assuming that you have written a program named abc.c and created executable abc.
Steps:
1. run your program from command line ./abc
3. get the PID processid of the program from PS aux | grep abc
3. start the gdb from command line
4. type following command on GDB prompt
(gdb) attach PID
where PID = your program's processid got from step 1.