Created
November 2, 2016 17:18
-
-
Save tiomoreno/e8e3719f58dea23679df5e1fd6047cb7 to your computer and use it in GitHub Desktop.
Retornando e alterando o nome do processo atual com python. Sem utilizar libs externas.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import ctypes | |
from ctypes.util import find_library | |
# Instanciando a libc | |
libc = ctypes.CDLL(find_library('c')) | |
# Setando as flags para definir e retornar o | |
# o nome do processo | |
PR_SET_NAME = 15 | |
PR_GET_NAME = 16 | |
# Define o nome do processo atual | |
def set_proc_name(name): | |
libc.prctl(PR_SET_NAME, name) | |
# Retorna o nome do processo atual | |
def get_proc_name(): | |
name = ctypes.create_string_buffer(16) | |
libc.prctl(PR_GET_NAME, name) | |
return name.value | |
# Definindo o nome do processo atual | |
set_proc_name("PyProcessName") | |
# Criando o loop para o processo | |
while True: | |
print get_proc_name() | |
time.sleep(1) | |
# O processo com o nome alterado pode ser consultado | |
# via bash atraves do comando | |
# ps -A | grep PyProcessName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment