[Techtalk] Help!

Sophie sophie at cats.meow.at
Wed Oct 2 16:45:45 EST 2002


On Wed, Oct/ 2/02 02:12:14PM +0100, Maria Blackmore wrote:
> On Wed, 2 Oct 2002, Sasha A Mclaughlin wrote:
> > I was having an issue with funtions and scripts.  I was supposed to be
> > writing a function to have my PS1 show my pwd everytime I changed
> > directories.  I swear, it took 2 hours. 
> 
> Everyone has to start somewhere :)
> 
> > Also, I before this class I had never written a script.  Everything we do
> > is in bash, so if there are any bash gurus out there, I could use your
> > help with general scripting questions.  Thank you all for responding to
> > my message.  If you've done some scripting and can help me write a script
> > to show the processes of the current user, you'd be saving my life.
> 
> by default, just "ps" by itself will show all the processes for the
> current user.  if not, something like "ps aux | grep $USER" should do the
> trick. ($USER is the environment variable showing the current user)

Most implementations of ps take -u or -U (or similar :) to list only that user's processes, so you dont need to filter output through grep. So something like:

ps -u $USER

Would list all of that user's processes. You can choose what information you want to display, too, for example to show the percentage of cpu time being used and the command line arguments for my processes:

cats% ps -o pcpu -o args
%CPU COMMAND
 0.0 /usr/bin/zsh
 0.0 ps -o pcpu -o args
cats%

It has alot of options for sorting etc, detailed in the man page.

So, you dont really need a script to show the processes of a user... but what do you need to script?

- sophie



More information about the Techtalk mailing list