My code shell script does not list all user processes

0

Why does not my code list all user processes? I made a script to delete processes from a user, it's exercise ... Well basically I made a whoami and I got into a variable, after that I made a ps -aux | egrep $ variable, and it returns processes but does not return all of the user does anyone know why? Here is the code, the part of if commented is to terminate the process with the given name, it seems like beast but I am starting in shell script so I am not getting

#!/bin/bash

variavel='whoami'

ps -aux | egrep $variavel

echo "Digite o nome do processo que deseja matar: "

read nome

clear

for processo in $(ps -aux |egrep $variavel |xargs -n1)
do
# if [ $nome == $processo[9] ]; then
#killall $nome
# echo "Processo morto"
# fi
    
asked by anonymous 31.03.2017 / 02:47

2 answers

0

Use this way:

ps -fu $(whoami)

Read more about ps here

    
31.03.2017 / 20:47
0

Try to use ps auxf instead of just ps aux

The ps auxf command usually shows all users, not even being logged in as root

If you want to look up processes for a particular user you can do the following:

ps auxf | grep "nomeDoUsuario"
    
06.04.2017 / 18:22