About MeCurriculumLicensePortfolioProjectsPublicationsBD-blog

Posts Tagged ‘C language’

I'm very pleased to announce the final release of my tiny C Unix Shell. Every requirement has been satisfied. I hope I will find the time to expand it

http://bd-things.net/projects/bd-shell/

 
 

Release Candidate 2 for my C shell is out. This is a real release candidate, code is frozen and hopefully this one does not have serious bugs like RC1. As you may know, RC1 has been retired because of a bug causing a segmentation fault when launching short commands in background. Let's see why this happened. The following schema summarizes what happens when a program in background is launched:

Schema for BD-shell, anatomy of process handling

Schema for BD-shell, anatomy of process handling


As you see, there is a non-synchronous function that is called when the child exits, the SIGCHLD handler.
What if the background command is very short, like ls? It may happen that SIGCHLD is thrown before the job object creation. Bdsh RC1 did not manage this case, and crashed. RC2 fixes this and does not have relevant bugs according to my definition of 1.0.0 release.

Finally, go and grab the code!

 
 

UPDATE: due to a very serious bug, the rc1 has been retired and replaced by rc2
UPDATE: the release has been delayed for two days

I've just released the release candidate for the final version of the Unix shell written in C language. Now with a very cleaner code and a lot of bugs fixed!

Download it!

 
 

I'm very proud to announce that the first beta version of the final release of BD-shell is ready and available for download.
As always you can find it on the project page.
Remember that this has to be considered as a bug hunting release, every requirements has been successfully covered but I cannot test it so often as I would like to..
Grab the code while it's hot!

 
 

BD-shell is a project I started about a month ago, which aims to implement a tiny, simple, clean unix shell written in C. The Operating Systems Course at my University requires this project as part of the assesment.
I decided to publish the source code and to release it under the GPL, for two reasons:

  1. Free software is better! Others can learn something from what I learned
  2. Free software is better! I can learn something from what others learned

As always, I accept every kind of suggestions!

Learn more about the project and download the code at this page:
http://bd-things.net/projects/bd-shell/

 
 

Time for two new C programs! At the DSA course I learned something about Hash Tables and collision resolutions.
I just implemented insert/search/print operations.

The first source code is an implementation of a Hash Map with open addressing (linear probing) as collision resolution method.
The following are the interesting functions of the program. As always, take a look at the source code for comments:

// hashMapLinear[] is the hash map
void linearProbingInsert(int value){
    int probe = hash(value);
    while (hashMapLinear[probe]!=0){                            
        probe = fmod((probe+1),SIZE_HASH_MAP);
    }
    hashMapLinear[probe] = value;
}

int linearProbingSearch(int value){
    int probe = hash(value);  
    int i;
    for(i=0;i<size_hash_map ;i++){    
        if(hashMapLinear[probe]==value)
            return TRUE;                            
        probe = fmod((probe+1),SIZE_HASH_MAP);              
    }
    return FALSE;                                          
}
 

Download: hash-map-linear-probing.c

The second program is an implementation of a Hash Map with chaining as collision resolution method.
Interesting functions:

// t_hashTableNode is a struct that is created as single linked list
void chainedHashInsert(int value){
    int probe = hash(value);                        
    if(hashMapChained[probe] == NULL){          
        hashMapChained[probe] = malloc(sizeof(t_hashTableNode));
        hashMapChained[probe]->value = value;
        hashMapChained[probe]->next = NULL;
    }else{
        t_hashTableNode *hashTableNode = hashMapChained[probe];
        while(hashTableNode->next!=NULL){
            hashTableNode = hashTableNode->next;
        }
        hashTableNode->next = malloc(sizeof(t_hashTableNode));
        hashTableNode->next->value = value;
        hashTableNode->next->next = NULL;
    }
}

int chainedHashSearch(int value){
    t_hashTableNode *hashTableNode = hashMapChained[hash(value)];
    while(hashTableNode!=NULL){
        if(hashTableNode->value==value){
            return TRUE;
        }
        hashTableNode = hashTableNode->next;
    }
    return FALSE;
}
 

Download: hash-map-chaining.c