shell commands

Hi Experts,

 I have a couple of questions as I am new to shell programming and I am very much learning now.

1) what is the difference in the command . and sh in executing a shell script. Understand that both executes a sheel script.

2) Understand ps gives the list of process running on the shell. Is there is a command or way to find a particular process whihc is taking lot of memory and keeps on buiding up the memory and blocking other processes from accessing the memory.

Please help me on this. If I come across some other problem , will let you know.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

1) . sources a file within the current instantiation
sh starts a new shell,

2) Obviously you expect that there is one "specialiced" tool for any task, This is as far from the unix way as one can get. You know there is ps so you have to combine it with another tool. Just an example the output of ps -aux looks like this here:
root         1  0.0  0.0   6036   548 ?        S    06:40   0:00 init [3]

You see the different columns? Now you run some tool on this field e.g awk
So we are looking on things where the Mem column is large then 5 MB then print this line

ps aux | awk 'NR > 1 { if ($5> (5 * 1024 * 1024)) { print $0} }'

The power from Unix comes to a very large extend from this facilities to combine diverse methods. Just another example if you want to know how many things are in a directory you probably write somethign like ls * | wc -l
There is no "count entries in directory" there.

what you will have to check are the zillions of optoins for the diverse tools e.g if you want to sort the output ordred by the neede virtual size you write something like:

ps aux --sort %mem or something similiar (not tested)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nmretdAuthor Commented:
Thanks for the reply . caould you please ler me know how is exec command different from . and sh

1) . executes the script within the calling shell, all variables in the sourced file are set/changed in the calling shell
   sh starts a new process, anything done there is private to that process and does not effect the calling sh (except permanent changes like files)

2) ps does not show the processes of the shell but of the system!
  see man ps for details (even how to get the amount of memory
  probably you want also use vmstat or top, see man-pages what they provide differnt/additional to ps
nmretdAuthor Commented:
Thanks for the response. I wrote a program to check the number of parametes passed, the script as below (argcheck)

if [ "$#" -ne 2 ]
        echo " Usuage: 2 args expected "
        exit 1

when I executed the above script as '. argcheck' I am not getting any message whihc I am expecting.

I am getting the expected message ' 2 args expected' when I am running it as ' sh argcheck' . Please advise on the 2 different behaviour.

Thanks in advance.
sourced files do not accept arguments (well, not really true: some shells behave different, but i.g. no arguments are read)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.