U
    Uc                     @   s(   d Z ddlZddlZdd Zdd ZdS )zFA tiny stand alone library to change the kernel process name on Linux.    Nc                   C   s   t tjtjd  dS )zDSets the process name to something better than 'python' if possible.r   N)set_kernel_process_nameospathbasenamesysargv r   r   5/tmp/pip-unpacked-wheel-yg88_g5m/absl/command_name.pymake_process_name_useful   s    r
   c                 C   s   t | ts| dd} z,tdd}|| dd  W 5 Q R X W n tk
r   zddl}W n tk
rv   Y Y dS X z|d}W n tk
r   Y Y dS X |	d}|	d}z|
|| ||| W n tk
r   Y Y dS X Y nX dS )	a  Changes the Kernel's /proc/self/status process name on Linux.

  The kernel name is NOT what will be shown by the ps or top command.
  It is a 15 character string stored in the kernel's process table that
  is included in the kernel log when a process is OOM killed.
  The first 15 bytes of name are used.  Non-ASCII unicode is replaced with '?'.

  Does nothing if /proc/self/comm cannot be written or prctl() fails.

  Args:
    name: bytes|unicode, the Linux kernel's command name to set.
  asciireplacez/proc/self/commwbN   r   z	libc.so.6)
isinstancebytesencodeopenwriteEnvironmentErrorctypesImportErrorCDLLc_ulongZprctlAttributeError)nameZ	proc_commr   libcZpr_set_nameZzeror   r   r	   r      s(    
 



r   )__doc__r   r   r
   r   r   r   r   r	   <module>   s   