Question: how gdb attach to process?
Answer: Find the process id (pid) with the ps command: $ ps -C program -o pid h pid. Replace program with file name or path to the program.
Attach GDB to this process: $ gdb -p pid. Replace pid with an actual process id number from the ps output.