Saturday, 27 April 2013

Use ulimit to Increase your system stack size

Currently I was testing my quick-sort program with a large number of data. It performed well when the data were random but when I used sorted or reversely sorted data then after some time the program stopped showing a message of segmentation fault. I was wondering why such type of exception happened. I was checking whether it was accessing any illegal memory location or not. But I didn't find anything of this kind. Then I found that default memory size for system stack is 8M.B in my memory and it was not sufficient for the program to operate on the given data. Then I found the ulimit command in shell that enhances the memory size for the system stack and it helped me to successfully run my program. ulimit provides control over the resources available to the shell and to processes started by it, on systems that allow such control. The -H and -S options specify  that the hard or soft limit is set for the given resource.  A hard limit cannot be increased by a non-root user once it is set; a soft limit    may be increased up to the value of the hard limit.  If neither -H nor -S is specified, both the soft and hard limits are set. There are some options that I found useful:
 -a     All current limits are reported
 -b     The maximum socket buffer size
 -d     The maximum size of a process's data segment
 -e     The maximum scheduling priority ("nice")
 -f     The maximum size of files written by the shell and its children
 -s     The maximum stack size
 -T     The maximum number of threads

If limit is given, it is the new value of the specified resource (the -a option is display only).  If no option is given, then -f is assumed.  Values are in 1024 byte increments. For example if you want to assign 200M.B to your system stack then you need to type:  
[subhendu@localhost ~]$ ulimit -Ss 204800
To know the current limits type: 
[subhendu@localhost ~]$ ulimit -a

Tuesday, 23 April 2013

Constant Pointer

  1. int const* ptr;
  2. const int*ptr;
  3. int *const ptr;
  4. const int* const ptr;
  5. int const*const ptr;

Sunday, 21 April 2013

Function returning pointer.

char *fun()
    return ("samsung India");

int main()
    return 0;

Short-circuiting in Logical AND

int main()
  int a;  
  a && printf("%d",a) && printf("LOL");  
  return 0;

Accessing Integer through character pointer

int main()
  int i=512;   
  char *c =(char*)&i;  
  return 0;

Saturday, 20 April 2013

Renaming large number of files

This post is just for those who are new to shell scripting. Today I stuck with a problem of renaming a large number of a pdf file. I was trying to rename them like "sequence-point-stack-1" only the last number will change and rest will be same for all files. So I tried to write a script that will help me and ultimately I succeed. Here is the code:

Wednesday, 17 April 2013

Falling in Love

Every body says "I fall in love" or "He fell in love". Why people falls in love? Is there any reason behind it?

Tuesday, 16 April 2013

Are we machine?

The topic I am going to share may seem to you funny and induced by some movie.  Many times our topic of discussion was distinction between the machine and Human. Some people argues that the things that distinguishes us from the machines are power to think,power to feel. I can feel pity on someone and I may help him though I was instructed to harm him, but a machine can't,It will do as it was instructed. It feels reasonable upto certain distance to me. Yes machine can not feel and can't think. Wait a minute are we sure that machine can't think? Actually I believe machines can think provided that they are given the power to think. How we do something? We observe the situation then analyse the situation and decides to do some thing. Machine also performs some  tasks just in the same way we do. Actually we tells them through their design how to perceive the situation and how to analyse the situation. But you may think our thinking power is not manipulated by some others or it is not pre determined that how we will react to a situation or we are?.  We all know about genes and how it controls our behaviour and characteristics. Is it not same as the embedding controls in machines design? I think as we embeds control information in a machine, our control information is also embedded in our gene. Actually all the things we do are governed by some rule. Same for how we feel. Maybe how we will feel something or someone is all embedded in our  gene. In which situation will we cry or laugh is predetermined, which food will we like, what kind of movie or songs will we like or which kind of people will we like is all predetermined. We are just following the rules according to the situation. If we are feeling sympathy on someone or even falling in love of someone, we are just following the rules. If we can design a machine where we can embed all these kind of control instruction then machines will act as human acts. But due to our limited knowledge we have not been able to read all kind of instructions in our gene, but when we will be able to that we might design a machine that will act as a human accurately. So all that I want to say is that Human body is a big and complex machine (may be controlled by some other ).

Wednesday, 3 April 2013

Way back to home

On the occasion of Holi, we all were returning home for the holidays from BHU. Though the holidays were of three days we extended it to 7 days. As we have nothing but a project work in this final semester so we didn't got much problem to extend the vacation. We had reserved our tickets one month before the holidays. Our train time was on the very dawn so I decided not to sleep at night and sleep on the train. Generally we sleeps not before 3 to 4 a.m , so I decided better not to sleep as it will be painful to wake up so early. As we are on the last semester and we must leave the hostel just after the semester examination we had a lots of luggage (mainly winter clothing ) with us to reduce the unnecessary things on hostel. The train was on time but the compartments were so crowded that it took us near about half of an hour to reach our seat. Of course most of the people didn't have legal tickets otherwise compartment would not be so crowded. When we reached our seats we found those well occupied by others without a valid ticket. It was their greatness that they offered us to seat on our reserved seat. Seating on that overcrowded compartment with a scorching sun I decided never to reserve any train ticket that runs on day time. However the train took us to our destination on time. From that place we all will go on different ways. I had to take another train that will take me to home. I had some notes of hundred rupees and change of four rupees only. But unfortunately my ticket was of fifteen rupees and the counter responded as I feared “get a change of one rupee” . Now I was on real trouble. I had two weighty luggage bags and also my laptop bag. Where should I get a change of hundred rupees? For that purpose I need to go to the nearby stalls and buy something. But with those heavy bags I found it hard to find my way to the stalls as in Howrah station stalls are at a distance from the station and to access the stalls that are inside the station I need a ticket which I didn't have at that time. So I waited there for some time then a man came to me to ask me if I need reservation tickets. I told him about my misery and it is kind of him that the man gave me one rupee. Then I got my ticket and went to the platform to take train. It was late enough. If I am late much then I will not get any bus from the rail station. Then I heard that most of the trains have been cancelled on our route due to the maintenance work on a particular station of that route. Then I waited for the last train with all other people, no, I better say a crowd that can't be fitted on a single train. As obvious I couldn't even reach the train. Then what? One of the last options. I went to room of my brother and next day in the morning I and my brother both went home. Really the journey was very tiresome.