0

Suppose i want to select 6547 from this output of "ps -eaf" command, how do i do it? I want to select that value and give it to "kill" command to kill that process.

root      6547     1  0 Aug07 ?        00:00:00 
root     14805     2  0 Aug07 ?        00:00:00 
root     17443 30043  0 16:21 pts/0    00:00:00 
sattu
  • 632
  • 1
  • 22
  • 37

1 Answers1

1

You may have to write a small shell script - which will basically contain below option -

    pidList=`ps -eaf | awk ' print $2'`  
    for pid in pidList  
    cmd="kill -9 $pid"  
    `$cmd` 

Now based on your critieria (like process name, user etc) you can take action for that specific process. So the jist here is to use awk command to get your exact column.

kumar_m_kiran
  • 3,982
  • 4
  • 47
  • 72
  • 1
    It worked with few changes:`ps -eaf | grep 'processname*' | awk '{print $2" "$1 "\n"}' | grep 'username*' | awk '{print $1}'` gave me exact value. I suppose you forgot {} in awk – sattu Aug 22 '13 at 00:45
  • Try to use ps with -U option if you need it for only specific user. That would be even better! – kumar_m_kiran Aug 22 '13 at 04:24