3 Nisan 2011 Pazar

Installing MySQL Server to Ubuntu

Installing MySQL Server to Ubuntu

20 Mart 2011 Pazar

Normalize Your Database with NF rules.

The Normal Form rules are the basic rules that are created by the Relational Database concept creater Edgar F. Codd. The main purpose of these is to create database tables that do not have redundancy for the data inside. There are basically three NF variations 1NF, 2NF, 3NF (Actually now on it goes up to 6NF by other theoreticians but basic structure is based on 1NF 2NF 3NF) .

1NF points out:
- Table should not have columns that are based on same data
- Create separate tables for each group of related data and identify each row with a unique column (the primary key).

Example:
(Manager, Employee1, Employee2 ) are the columns but there are two Employee column that violate rule one.

(Manager, Employee) is good solution but it violates still second rule.

(Manager, EmployeeID) is intuitive solution since each Employee has only one Manager. Now our table is proper for 1NF.

2NF points out:
- Remove subset of data that causes multiple rows includes same information and create seperate table for them
-Use foreign keys to relate the tables that are newly created and previous one

EXAMPLE:
(EmpID,FirstName, LastName, City, Zipcode, ) is our table but if there are two employee with same city so zipcodem it makes two row with redundant data. So it is more appropriate to use another table that includes cities and correspondence zipcodes. In addition new new structure makes easier to add, remove or update address information. Instead of updating all the rows that have same city and zipcode, we just need to update one row in the new table.
(EmpID, FirstName, LastName, AddID) (AddID, City, ZipCode)

3NF points out:
-Each attribute in the table must be fully determined by a key, separate other columns to other table.

EXAMPLE:
(CustomerID, OrderNum, UnitPrice, Quantity, Total) in this table all the attributes are fully depended to CustomerID but the Total. Total is determined by the UnitPrice*Quantity so it is not fully depended to key. It can be deleted.
(CustomerID, OrderNum, UnitPrice, Quantity) is new table

11 Mart 2011 Cuma

Convertion the integer to string in C!!

It has really basic way to do. Here is the code!

int main{
int i = 232324;
char numChar[10];
sprintf(numChar, "%d", i);
return 0;
}

5 Mart 2011 Cumartesi

MCU 8051 IDE for developing 8051 assemble code for UBUNTU!


Here is a Assembler IDE for UBUNTU which releases from WINDOWS to freedom.
It is really good IDE and it provides some more options for other processor types. You can develop code and simulate it with great functions. I really suggest you to use it.

Here is the link: http://mcu8051ide.sourceforge.net/

3 Mart 2011 Perşembe

Using Pipes for IPC in C

I am developing a program that utilises the pipe system of POSIX for my Operating system course. I want to share my experience with you. There might be some flaws in my explanations and in that case please WARN ME?

Then, lets start some explanation for beginning. Pipes system is used for (Inter-process Communication) IPC between related processes. Related means that the processes having parent-child relation or sibling relation. It is not possible to use pipes for unrelated process communication. In addition the another limitation of the pipes is that one pipe just gives uni-directional communication between processes so if you want to have both direction communication, you might use two distinct pipes that have different directions in the way of sharing data (one pipe to send data form parent to child, one pipe to send data from child to parent). Another restriction of the pipe system, it is not the best way to share big data between processes (Using shared memory structure may be suitable) but it is the most common way.

Now here the basic process of coding in C:

First #include stdio.h(standard input output library) stdlib.h (standard library) unistd.h(POSIX depended functions library)

Create the pipe with "pipe(fd)". fd is the array to keep the file descriptors that are returned by the function. These descriptors points the "files" that are created after the function to provide read and write. (By the way, pipes are respected as files in the system. Thus each read and write action manipulated like file objects). Here is the code:

int fd[2];
pipe(fd);


After you create the pipe, if you "fork()" the process, it creates a child process that inherits all the information about the pipe so it is okay to communicate with the pipes.

I give an example code taken and little manipulated by myself form a pdf. In this implementation, by using the file descriptors we create file objects. In that way, this is possible to use standard C functions to read and write pipes. (Also you can get the PDF file from here).

Here
the link for below code:

#include
#include
#include
#include

/* Read characters from the pipe and echo them to stdout. */

void
read_from_pipe (int file)
{
FILE *stream;
int c;
stream = fdopen (file, "r");
while ((c = fgetc (stream)) != EOF)
putchar (c);
fclose (stream);
}

/* Write some random text to the pipe. */

void
write_to_pipe (int file)
{
FILE *stream;
stream = fdopen (file, "w");
fprintf (stream, "hello, world!\n");
fprintf (stream, "goodbye, world!\n");
fclose (stream);
}

int
main (void)
{
pid_t pid;
int mypipe[2];

/* Create the pipe. */
if (pipe (mypipe))
{
fprintf (stderr, "Pipe failed.\n");
return EXIT_FAILURE;
}

/* Create the child process. */
pid = fork ();
if (pid == (pid_t) 0)
{
/* This is the child process.
Close other end first. */
close (mypipe[1]);
read_from_pipe (mypipe[0]);
return EXIT_SUCCESS;
}
else if (pid < (pid_t) 0) {
/* The fork failed. */
fprintf (stderr, "Fork failed.\n");
return EXIT_FAILURE; }
else { /* This is the parent process. Close other end first. */
close (mypipe[0]);
write_to_pipe (mypipe[1]);
return EXIT_SUCCESS;
}
}

Also there is another way of using pipes by using "popen" as named pipe implementation. It is more generalised way of doing and avoids all the file object creation. You can get more info from the pdf.

Fine document for IPC alternatives.

http://tldp.org/LDP/tlk/ipc/ipc.html

27 Şubat 2011 Pazar

IPC (Interprocess Communication) implementation example.

This example code illustrates the basic implementation of IPC mechanism that is provided by POSIX API.


#include
#include
#include

int main(int argc, char **argv)
{
int segment_id;
char *shared_mem;
const int size = 5096; // in bytes

//create shared mem.
segment_id = shmget(IPC_PRIVATE, size, S_IRUSR|S_IWUSR);

//attach the shared mem. to the process in Write Read mode.(0 argument)
shared_mem = (char * )shmat(segment_id, NULL, 0);

//write the data to the shared memory.
sprintf(shared_mem, "This is the shared memory example coded by Eren Golge. Regards!!");

//read the data from
printf("*%s \n", shared_mem );

//detach the segment from process
shmdt(shared_mem);

//delete the shared mem. segment form memory
shmctl(segment_id, IPC_RMID, NULL);

printf("End of code");
return 0;
}