Unix 101: Unix processes

I’m sure you’ve heard people tell you that Unix (and Linux) is a multiuser/multitasking operating system. But, what does that mean ?

Well, for one, you can create multiple users on linux and let all of them use the machine at the same time, by letting them login remotely (We’ll cover this later). And thus, Linux is a multiuser operating system.

Multitasking is a little more complicated.

You see, a Unix system at any time is always running more than one programs simultaneously. Ah, but I am only running my browser, you ask ? Well, yes and no. The browser is the only program that you are running but there is more to the operating system, than just the browser, right ? For example, the graphical interface that you’re running. And what if there are more people working on the same system (the multiuser part of it), then all of them would be running their own programs, right ? So, to cut things short, any Linux or Unix system at any time is always running multiple programs/tasks and thus, is a multitasking system. How does it do that ?

To make your browser run and take input from you or display images, a lot is going on in the background which you don’t see. Multitasking is one of those things. The operating system partitions the memory so that no other user can see the email that you’re working on, it makes sure that the email client has the resources it needs to send the email when it wants and various other sundry tasks. If you’re confused, I understand. These are more complicated operating system task should probably be reserved to the Unix 201 or 301 course :-)

Today we’re just going to play around a bit with processes on a Linux box.

To list all the processes running on your machine, use the following command:

$ ps

The output will be something like this:

  PID TTY          TIME CMD
 8551 pts/0    00:00:00 bash
 8600 pts/0    00:00:00 ps

That’s some terse output, isn’t it ? Well, what it tells you is that there are two process running on your system and those are bash and ps (ps is the command you ran to get this list, so while it was getting the list, it was one of the processes running and so it included itself in the list). The other thing that the output tell you is the process ID (PID) of the processes. This is an identifier that the system uses to identify processes internally. The PID for bash is 8551 and the PID for ps is 8600. The next time you run this command, the ps command will have a different PID because once the ps command has executed, the operating system clears all resources used by it and that includes the PID. When the command runs again, it gets all shiny, brand new resources.

Now, if you’ve noticed, the above ps output only shows you the commands that you are running. If you want to see all the processes that are running on the system at any time. Use the ps command with the following options:

$ ps -ef

That, I’m sure, is a lot more info that most of you are ready to digest, right ? If, the answer is No, then you shouldn’t be reading this :-)

Jokes apart, the basic info given in the output is the same but there are some other fields which might be interesting. You can read the man page for the ps command to read about all the fields or the various other options that the command supports. There are dozens and its not practical for me to cover all of them here.

We’ll be covering the ps command in more detail in a later post and learn to do more cool things with it.

Subscribe to this blog using your RSS reader or by Email.

This entry was posted in OpenGuide and tagged , , . Bookmark the permalink.