[Wolves] Hello...

Adam Sweet adam at adamsweet.org
Mon Jun 15 19:03:54 UTC 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Octavio Augusto Sánchez Velázquez wrote:

> El lun, 15-06-2009 a las 10:40 +0100, Adam Sweet escribió:

^^^ Gotta love that in the list archive :) ^^^

> > Welcome to the LUG :) Are you a Spanish student coming to
> > Wolverhampton University?
> I am from Mexico, not from Spain, but yes I'm going to study to
> Wolverhampton University.

My apologies :) You'll probably get that assumption a lot here.

> > Now awk out the first field which contains the process IDs:
> >
> > adams at selenium:~$ ps ax | grep apache | grep -v grep | awk {'print $1'}
> > 3933
> > 11133
> > 11135
> > 11136
> > 11138
> > 11139
> >
> > Awk uses tabs as field separators, so I'm telling it to pull out the
> > first one.

> Yes, I get know that sed s///g changes the strings of the first // for
> the second //, this get's me another doubt, what about tr??? awk, I
> really don't get it I usually copy and paste it and that's all. In your
> example I didn't get what you were doing because I didn't know what ps
> was (nothing that man ps couldn't solve), I usually use top insted,
> but from now on I will use this ps sweet, hehe thank you.

Top shows you continually updating resource usage, like CPU usage,
memory usage, system uptime, how much time is spent actually running
user level stuff, how much time was spent in the kernel, how much was
idle and how much was spent waiting for i/o (usually disk in my
experience). It also shows you a list of processes consuming the most
resources, ordered by CPU utilisation. It doesn't show you all running
processes, just the ones which are using the most resources and which
will fit on the screen.

ps shows just show you a list of running processes and spits them out to
screen. By default ps just shows you your own processes, with various
options you can get more information. The most common usage of ps is
with the options aux (the - character which normally goes before command
options isn't necessary with ps). So what I was doing above was printing
out the list of all processes, grepping for ones which contained apache,
remove grep itself from the list and then. The ps output uses tab
separated fields and awk by default knows how to pull information out of
data this format, so I was getting awk to give me the contents of the
first field. A real world usage scenario would be that you have a system
service (known as a daemon under Unix) that has gone a bit crazy and
won't die, so you need to kill it manually. Daemons like apache have
more than one process, so you want to know the process IDs of all apache
processes so you can kill them.

tr does similar things to sed, but you can do things like changing lower
case to upper easily, I ripped the following example from
http://www.linfo.org/tr.html

The following would replace every upper case letter in a file named
file7 by its lower case counterpart and write the result to a file
called file8:

cat file7 | tr '[A-Z]' '[a-z]' > file8

The important thing is you don't have to worry too much about learning
how to use every single command that you hear about, just knowing what
they do is enough and a quick play with each will serve you well should
you ever need them. I'm a Linux sysadmin and I use probably the same 10
commands every day and maybe use 30% of the available commands on the
average Linux system in a year. Quite often, for programmers, it's
easier to do something in perl, python or PHP than it is to figure out
the Unix commands and their syntax so don't worry too much :)

Regards,

Adam Sweet

- --

http://blog.adamsweet.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAko2mxAACgkQRi1ZcmvD37d7yQCfQnFeHH0NidqaqW8MSc4XKrzz
VXkAoIaI4+EXmIKo5vkRqMGJGI3RQAXo
=oI68
-----END PGP SIGNATURE-----



More information about the Wolves mailing list