Ravi Teja Paruchuri
Ravi Teja Paruchuri

Reputation: 35

How do I find the program process id number to kill program automatically in assembly on Linux?

With this, I can find the process id number of the program:

ps -auwx | grep vlc | awk '{print$2}' | head -n 1

In an assembly program, how do I find the process id dynamically?

section .text
global _start
_start:
      mov rax,62 ; syscall for kill
      mov rdi,5265 ; pid of vlc media player
      mov rsi,9 ;signal
      syscall
      mov rax,60
      mov rdi,0
      syscall

Upvotes: 0

Views: 1030

Answers (1)

fuz
fuz

Reputation: 93082

This is tedious to do. What you need to do is walk through the /proc file system, reading the cmdline files for each process to determine which process is the one you are interested in. You might also need to implement some sort of string matching procedure so you can match /usr/bin/vlc as well as vlc.

See proc(5) for documentation.

Upvotes: 1

Related Questions