DEV Community

Kamal Mustafa
Kamal Mustafa

Posted on • Updated on

How is a program on linux executed?

Just a self notes to refresh my mind on this, as it keep popping from time to time and I have to google it to answer the question.

Injecting into running process

  • Attach to the a current running process by gathering its PID.
  • Send a SIGSTOP to the program to halt it's execution
  • Dump its registers (specifically rip/eip)
  • Write your code to the stack where rip is pointing to.
  • Send a SIGCONT to the program to return control.
  • Profit.

Also look into how strace work.


  • main() was defined in libc - the function in libc that assume the first function in C program to call is named main().
  • What address to load that contain the start of the program is defined in ELF headers.

Other similar topics

Top comments (2)

v6 profile image
🦄N B🛡

// , For more perfect grammar, I would do "How is a program on linux executed?"

Thanks for posting this, though.

k4ml profile image
Kamal Mustafa

Thanks. I'm not a native speaker :)