killare processi vecchi

Linguaggi di programmazione: php, perl, python, C, bash e tutti gli altri.
Avatar utente
ing_magnus
Prode Principiante
Messaggi: 48
Iscrizione: domenica 2 dicembre 2007, 12:30
Contatti:

killare processi vecchi

Messaggio da ing_magnus »

Ciao ragazzi,
avrei bisogno di killare n processi del tipo:

...
postgres 6331 0.0 0.0 21456 2320 ? S 14:43 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
postgres 6331 0.0 0.0 21456 2320 ? S 14:44 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
postgres 6331 0.0 0.0 21456 2320 ? S 14:45 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
postgres 6331 0.0 0.0 21456 2320 ? S 14:46 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
postgres 6331 0.0 0.0 21456 2320 ? S 14:47 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
...

in base al più vecchio.

Le parole chiave nel processo dovrebbero essere nomeutente e postgres.

Lanciando un comando del tipo:

killa 4 nomeutente

la shell dovrebbe generare il seguente risultato ( lanciando ps aux ):

...
postgres 6331 0.0 0.0 21456 2320 ? S 14:47 0:00 postgres: nomeutente nomedatabase 62.149.206.XXX idle
...

Mi aiutate a realizzare la cosa?

:(
Avatar utente
Just_Cause
Prode Principiante
Messaggi: 15
Iscrizione: mercoledì 14 maggio 2008, 18:39
Località: Kernel
Contatti:

Re: killare processi vecchi

Messaggio da Just_Cause »

Per killare un processo basta scrivere kill -9 numero del processo se ti dice funziona non permessa
loggati al terminale root e scrivi kill -9 numero del processo

Ciao
Avatar utente
ing_magnus
Prode Principiante
Messaggi: 48
Iscrizione: domenica 2 dicembre 2007, 12:30
Contatti:

Re: killare processi vecchi

Messaggio da ing_magnus »

Beh si, questo lo so. Il problema era killare i processi vecchi meno alcuni.

Comunque ho risolto così ( lo posto qualora serva anche a qualcun'altro ):

Codice: Seleziona tutto

if [ "$1" = "" ]; then 
echo "Specificare username" 
exit 1 
fi 
if [ "$2" = "" ]; then 
echo "Specificare processi da lasciare attivi." 
exit 1 
fi 

echo "---> Output ps aux" 
ps aux | grep "$1" | grep "postgres" | grep "idle" 
ps aux | grep "$1" | grep "postgres" | grep "idle" | awk '{ print $2}'  > kill_processo.tmp 

cp kill_processo.tmp _kill_processo.tmp 

NUMERO_RIGHE=`wc -l _kill_processo.tmp | awk '{ print $1 }'` 

NUMERO_RIGHE=`expr $NUMERO_RIGHE + -$2` 

echo "---> Cancellare $NUMERO_RIGHE processi." 

X=1 
while [ $X -le $NUMERO_RIGHE ] 
do 
   PID=`head -n 1 _kill_processo.tmp` 

   echo "kill $PID" 
   kill $PID 

   NUMERO_RIGHE_TMP=`wc -l _kill_processo.tmp | awk '{ print $1 }'` 

   RIGHE_ERASE=`expr $NUMERO_RIGHE_TMP + -1` 
    
   tail -n $RIGHE_ERASE _kill_processo.tmp > _kill_processo.tmp2 
   cp  _kill_processo.tmp2 _kill_processo.tmp 

   X=`expr $X + 1` 
done 

rm -f _kill_processo.tmp 
rm -f _kill_processo.tmp2
Scrivi risposta

Ritorna a “Programmazione”

Chi c’è in linea

Visualizzano questa sezione: 0 utenti iscritti e 7 ospiti