Sunday, June 30, 2013

How to list Unix Signals

A very simple command to list all the available in the system

kill –l

image

Technorati Tags: ,

Saturday, June 29, 2013

Some commands related to Process

1. nice:

It sounds nice isn’t it. This command is used to run a program with low priority

example; nice ls –l

2. nohup: (no hangup): This is used to execute the command even after logging out. We need to just prefix this command before the program to be executed.

3. Control Z: When we hit Control Z while executing any command, it will suspend the process, i.e. the process will stop temporarily. If we wish to resume the process, we can use the command fg. In case there are multiple processes suspended, we use “fg” with the PID. To find the PID, issue the command jobs

Control Z

image

jobs

image

The number in the square brackets is the PID. To retrieve the job, enter fg %1

image

image

kill.

To terminate the process issue the command kill pid. It sends the SIGTERM(15) signal.

image

To kill the last job, issue the command kill $!

You can even kill the login process!

kill –9 $$  (-9 is for force kill). The terminal will exit once the command is executed.

 

Technorati Tags: ,,,,,

Monday, June 24, 2013

Process Creation: Unix

The process creation consists of three phases:

Fork : When a process is said to be forked, it creates a copy of the process. The new process will have a new PID.

Exec:  Just creating a new process is not sufficient to execute it. The child process will require to overwrite the code and data of the parent process. This is known as ‘exec’. Note that the no new process is created here. This is just a mechanism to execute the process.

wait: The parent process would call ‘wait’ system call, which would suspend its execution and wait till the child process is complete.

One of the best example of process creation is the logging process.

In a multi user system, once system boots up, process 0 which is part of kernel process forks the init process and becomes the swapper process. The init process then spawns the getty process (which is get terminal- the terminal process). The getty process then execs the login program which waits till the user enters credentials which it validates. If login is successful, it execs the shell program else it exits and the init program again forks and creates the getty process. The below flow diagram would give a clear picture.

 image

Technorati Tags: ,,,

Sunday, June 23, 2013

Processes in UNIX

I would like to continue my mini tutorials in Unix/Linux. I will focus on the topic of Processes in this post. I will try to compile as many tutorials as possible in the next few posts on Unix covering basics and will move to advanced topics. This would be a learning experience for me as well.

Coming to the context..

Process is an instance of a program in execution. Its also called task or job. For example the command who would display all the users currently logged into Unix. Here the execution of the program who is a process. The actual program resides on the secondary memory (such as hard disk) while the process will be executed in the RAM. (In some cases memory may be allocated from secondary memory as well which is known as virtual memory).

Some key aspects of processes:

  • Process is “born” when it starts execution and is said to “die” when it completes execution
  • Kernel takes care of process management
  • Process communicates with other process through system calls
  • Process is created by the “fork” system call.

 

There must be some process which starts ‘fork’ as well. This is called parent process and the new process created is called child process. Each process is associated with “process_id”.  The First Process which gets created is Process 0 (called Parent process as told before), when the system boots up. After this process is ‘Forked’ for a child process, process 0 becomes ‘swapper’ process. This process is part of the kernel and will be used for scheduling other processes.

The child process is called ‘Process 1’ which is considered as ancestor of every process in UNIX and is called the ‘init’ process.

After the system gets logged in, the Kernel creates the SHELL process. Hence Shell is also a process and is associated with PID. To know PID type the below command:

echo $$

For example, in the below command:

ls –l | more

The parent process is the shell. ls-l is executed first and the output is fed to more which displays output one page at a time. Hence ls-l and more are two child processes here.

To know about the process states, issue the below command

image

    PID 1520 is the process id for the SHELL. PPIS is the parent id which is the process 1 (init). We can see the command ‘more’ has PPID 1520 (therefore a child process for the SHELL). We can also see the command ps –f itself. This presents a clear picture of the processes.  

In the next session we will discuss about how exactly is the process created,where fork comes into picture and so on.                           

Technorati Tags: ,,,

Sunday, June 16, 2013

Mysore memories

 

We went to Mysore yesterday after a long time. Some of its memories…

Mysore

image 

image 

Mysore is developing fast, as is evident from its planning and well maintained roads. Its a clean and green city with beautiful lawns and parks.

 

DSCN2023

mysore palace

Chamudi

                         Chamundi temple.

Friday, June 14, 2013

Money Plant!

We ‘planted’ Epipremnum aureum today. I want to observe its growth.. will post photos of its progress.

DSCN1977

Saturday, June 8, 2013

Sunday, June 2, 2013

State Border

I never keenly observed the border between two states. I went off for a long drive today towards the outskirts of Bangalore when I suddenly landed at the border of Karnataka and Tamil Nadu! I started through the Varthur road, towards Sharjapur and found myself at the national highway (NH-207).

IMG_20130602_115007                           

IMG_20130602_115101

Saturday, June 1, 2013

A Roman Holiday: A Memorable Masterpiece

One upon a time, a beautiful princess ruled a kingdom..
She had everything, riches, servants, ornaments,image, everything..
But there was one thing, the most important thing that she did not have: Happiness
And this was because she was lonely..
And one fine day, she escaped from the clutches of loneliness to find the real world outside.. and she stumbled across a man of her dreams.. and then an adventure began.
This is the simple story of this timeless classic.
image
image