My shell script does not list all user processes

Asked

Viewed 158 times

0

Why doesn’t my code list all user processes? I made a script to delete a user’s processes, it’s exercise... Good basically made a whoami and adiquiri in a variable, after that made a ps -aux | egrep $variable , and it returns processes but does not return all of the user anyone knows why? Here goes the code, the part of the commented if is to end the process with the given name, it looks silly but I’m starting in shell script so I’m 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

2 answers

0

Try to use ps auxf instead of just ps aux

The command ps auxf generally shows all users, including not being logged in as root

If you want to search processes of a given user you can do the following:

ps auxf | grep "nomeDoUsuario"

0

Use like this:

ps -fu $(whoami)

Read more about the ps here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.