Gerenciamento de Shared Memory no AIX e Linux (resumido)

Posted by kairo on Sun 13 April 2008

Shared Memory são áreas de memórias compartilhadas com outros processos (se permitido).
Uma definição mais detalhada pode ser vista aqui.

As vezes uma aplicação após um travamento pode ter falha no reestart devido a processos presos no Shared Memory. Tanto no AIX quanto no Linux existe a possibilidade de remover estes processos.
Basicamente utilizamos dois comandos:
ipcs - Verificar o shared memory
ipcrm - Remover do shared memory.

Abaixo segue a dica de forma resumida.

Listando processos no shared memory

# ipcs -a

Exemplo:

# ipcs -a IPC status from /dev/mem as of Sun Apr 13 20:15:25 GRNLNDST 2008 T ID KEY MODE OWNER GROUP CREATOR CGROUP CBYTES QNUM QBYTES LSPID LRPID STIME RTIME CTIME Message Queues: q 0 0x4107001c -Rrw-rw---- root printq root printq 0 0 4194304 0 0 no-entry no-entry 16:36:07 T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME Shared Memory: m 3145728 0x00004dbe --rw-rw-rw- root system root system 0 1848776 1822840 1802430 17:19:13 17:10:31 17:43:06 m 1048577 0xffffffff --rw-rw---- root system root system 1 4096 278780 278780 20:14:16 20:14:16 16:36:37 m 5 0x0382becc --rw-rw-rw- uxxxx gxxxx uxxxx gxxxx 0 4096 995570 2125946 14:28:49 17:22:40 18:39:36 m 12582924 0xffffffff --rw------- root system root system 0 557192 2121966 254178 15:14:02 15:57:39 15:14:01 m 12582925 0xffffffff --rw------- root system root system 0 557192 1900732 254178 15:14:02 15:55:09 15:14:01 m 12582926 0xffffffff --rw------- root system root system 0 557192 2121966 254178 15:14:16 15:58:39 15:14:15 m 15728725 0x0382be85 --rw-rw-rw- uxxxx gxxxx uxxxx gxxxx 0 4096 2142322 716904 15:21:09 14:51:57 17:47:09 m 36700248 0xffffffff --rw------- root system root system 0 557192 2293896 2293896 15:51:34 15:52:21 15:51:34

Dica 01: o CPID corresponde ao PID do processo no sistema operacional, exemplo:

m 5 0x0382becc --rw-rw-rw- uxxxx gxxxx uxxxx gxxxx 0 4096 995570 2125946 14:28:49 17:22:40 18:39:36

4096 é o PID do processo, que pode ser identificado pelo "ps -ef | grep 4096".

Removendo processo do shared memory

# ipcrm -m ID

Exemplo

# ipcrm -m 15728725 # ipcs -a IPC status from /dev/mem as of Sun Apr 13 20:19:48 GRNLNDST 2008 T ID KEY MODE OWNER GROUP CREATOR CGROUP CBYTES QNUM QBYTES LSPID LRPID STIME RTIME CTIME Message Queues: q 0 0x4107001c -Rrw-rw---- root printq root printq 0 0 4194304 0 0 no-entry no-entry 16:36:07 T ID KEY MODE OWNER GROUP CREATOR CGROUP NATTCH SEGSZ CPID LPID ATIME DTIME CTIME Shared Memory: m 3145728 0x00004dbe --rw-rw-rw- root system root system 0 1848776 1822840 1802430 17:19:13 17:10:31 17:43:06 m 1048577 0xffffffff --rw-rw---- root system root system 1 4096 278780 278780 20:18:16 20:18:16 16:36:37 m 5 0x0382becc --rw-rw-rw- uxxxx gxxxx uxxxx gxxxx 0 4096 995570 2125946 14:28:49 17:22:40 18:39:36 m 12582924 0xffffffff --rw------- root system root system 0 557192 2121966 254178 15:14:02 15:57:39 15:14:01 m 12582925 0xffffffff --rw------- root system root system 0 557192 1900732 254178 15:14:02 15:55:09 15:14:01 m 12582926 0xffffffff --rw------- root system root system 0 557192 2121966 254178 15:14:16 15:58:39 15:14:15 m 36700248 0xffffffff --rw------- root system root system 0 557192 2293896 2293896 15:51:34 15:52:21 15:51:34 m 28311641 0xffffffff --rw------- root system root system 0 557192 475312 475312 14:10:25 15:43:32 14:10:22 m 23068762 0xffffffff --rw------- root system root system 0 557192 1798238 1798238 15:49:36 15:52:32 15:49:36

Dica 01: Processo no shared memory em Defunct

O processos ficam com um "D" no inicio, exemplo:

m 23068762 0xffffffff D-rw------- root system root system 0 557192 1798238 1798238 15:49:36 15:52:32 15:49:36

Estes processos não podem ser removidos. :(


Comments !