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;
}

23 Şubat 2011 Çarşamba

Installing MySql to Ubuntu

Here are the steps that you need to follow:

1- Install the files that need to create a mysql database.

$sudo apt-get install mysql-server

2- Open the config file and comment out the line "bind-address = 127.0.0.1" as "#bind-address = 127.0.0.1". It makes your server available from internet.

$gksudo gedit /etc/mysql/my.cnf

3- Set the root password of the server and restart it.

$mysqladmin -u root password your-new-password

$sudo /etc/init.d/mysql restart

4- Install the "MYSql query browser" program

$sudo apt-get install mysql-query-browser

5- Program is installed in Applications > Programming, open it. Then type the necessary infos.

Server Hostname: 127.0.0.1
Username: root
Password: ******
Default Schema: (Empty)
Port : 3306

19 Şubat 2011 Cumartesi

Compiling Kernel Method 2 (As Debian Package)

Here another compilation method for Kernel installing.

First download wanted kernel source code from kerel.org

then extract the .tar file that comes from the website.

Here the terminal process.

Copy the old config file to the new Kernel to do not try for setting new kernel.
­cp -vi /boot/config-`uname -r` .config

Or if you want to set your kernel type:
sudo make menuconfig

Then compile and create the debian packages of the kernel. You can type anything instead of **** to define your kernel. "fakeroot" commands gives error, maybe you need to download and install from "software center".
fakeroot make-kpkg --initrd --append-to-version=**** kernel-image kernel-headers


There should be created two "debian packages" (most probably in desktop). Go that directory in terminal then type:
sudo dpkg -i linux-ubuntu-modules-2.6.24-16-generic_2.6.24-16.23_i386.deb
sudo dpkg -i linux-headers-lum-2.6.24-16-generic_2.6.24-16.23_i386.deb


Finally go to the boot directory to set the "grub" with your new kernel:

cd /boot
sudo update-initramfs -c -k 2.6.37+QD

sudo update-grub2
reboot

Ubuntu 32-bit and 64-bit comparison bencmark.

http://www.tuxradar.com/content/ubuntu-904-32-bit-vs-64-bit-benchmarks

17 Şubat 2011 Perşembe

Good Site to learn commands and some terminal programs to see Process Status of System

http://www.cyberciti.biz/faq/show-all-running-processes-in-linux/

Compiling a kernel source code and use it as the kernel of your linux OS.

get latest kernel source:

$ cd /tmp
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2


extract .tar file:

# tar -xjvf linux-2.6.37.tar.bz2 -C /usr/src
# cd /usr/src


Configure kernel respected to your computer:

# make menuconfig


Compile Kernel:

$ make


Compile Kernel modules:

$ make modules


Install the kernel modules as a root user:

$su -
#make modules_install


Install kernel:

#make install


Create initrd image for Grup program for using at boot time initialization:

#cd /boot
#mkinitrd -o initrd.img-2.6.37 2.6.37


Modify Grup config. file:

# update-grup


Reboot computer:

That's all:)

"grep" Tool.

It is a new tool that I discover and I guess it is also really beneficial for you (The CS'ers). It is to search a String pattern in all kind of documents and the tool gives you the all matching documents and the line numbers of matchings of these documents.
Here is the basic structure of the usage;

grep [options] pattern filieTypes

[options] side to activate some extra functionalities. You can see the documentation in terminal by typing "grep --help"

Here also an example which search "sys_getpid" string in the all file types in directories with subdirectories.




erogol@ubuntu:~/Desktop/linux-2.6.37$ grep -Hrni sys_getPid *
arch/microblaze/kernel/syscall_table.S:27: .long sys_getpid /* 20 */
arch/mips/kernel/scall64-o32.S:227: PTR sys_getpid /* 4020 */
arch/mips/kernel/scall64-64.S:168: PTR sys_getpid
arch/mips/kernel/scall64-n32.S:163: PTR sys_getpid
arch/mips/kernel/scall32-o32.S:259: sys sys_getpid 0 /* 4020 */
arch/avr32/kernel/syscall_table.S:36: .long sys_getpid /* 20 */
arch/xtensa/include/asm/unistd.h:281:__SYSCALL(120, sys_getpid, 0)
arch/xtensa/platforms/iss/include/platform/simcall.h:39:#define SYS_getpid 20
arch/s390/kernel/syscalls.S:31:SYSCALL(sys_getpid,sys_getpid,sys_getpid) /* 20 */
arch/sparc/kernel/systbls_64.S:25:/*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16
arch/sparc/kernel/systbls_64.S:101:/*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid, sys_getuid
arch/sparc/kernel/systbls_32.S:23:/*20*/ .long sys_getpid, sys_capget, sys_capset, sys_setuid16, sys_getuid16
arch/frv/kernel/entry.S:1212: .long sys_getpid /* 20 */
arch/x86/include/asm/unistd_64.h:98:__SYSCALL(__NR_getpid, sys_getpid)
Binary file arch/x86/kernel/syscall_64.o matches
arch/x86/kernel/syscall_table_32.S:22: .long sys_getpid /* 20 */
Binary file arch/x86/kernel/built-in.o matches
Binary file arch/x86/built-in.o matches
arch/x86/ia32/ia32entry.S:533: .quad sys_getpid /* 20 */
Binary file arch/x86/ia32/built-in.o matches
Binary file arch/x86/ia32/ia32entry.o matches
arch/m68k/kernel/entry.S:451: .long sys_getpid /* 20 */
arch/parisc/hpux/entry_hpux.S:51: ENTRY_NAME(sys_getpid) /* 20 */
arch/sh/kernel/syscalls_32.S:39: .long sys_getpid /* 20 */
arch/sh/kernel/syscalls_64.S:43: .long sys_getpid /* 20 */
arch/cris/arch-v10/kernel/entry.S:625: .long sys_getpid /* 20 */
arch/cris/arch-v32/kernel/entry.S:568: .long sys_getpid /* 20 */
arch/h8300/kernel/syscalls.S:37: .long SYMBOL_NAME(sys_getpid) /* 20 */
arch/ia64/kernel/fsys.S:61:ENTRY(fsys_getpid)
arch/ia64/kernel/fsys.S:92:END(fsys_getpid)
arch/ia64/kernel/fsys.S:782: data8 fsys_getpid // getpid
arch/ia64/kernel/entry.S:1489: data8 sys_getpid
arch/m32r/kernel/syscall_table.S:22: .long sys_getpid /* 20 */
arch/mn10300/kernel/entry.S:460: .long sys_getpid /* 20 */
arch/blackfin/mach-common/entry.S:1386: .long _sys_getpid /* 20 */
arch/arm/kernel/calls.S:32:/* 20 */ CALL(sys_getpid)
arch/m68knommu/kernel/syscalltable.S:41: .long sys_getpid /* 20 */
...

13 Şubat 2011 Pazar

A Good Writing About Boot Process for Linux System!

http://harrykar.blogspot.com/2010/03/ubuntu-system-administration.html

Using "strace" to see the Sys. calls executed with your written code.

"strace" is really effective utility for system administrators and coders to see the system calls that your program makes. It is really easy to use, just write to your terminal "strace programName" exp. "strace ./a.out" like ordinary compiled C code. It give output something like this; (I have interesting name of directory "01-um-getpid$" includes the a.out file. Do not be confused!)



erogol@ubuntu:~/Desktop/01-um-getpid$ strace ./a.out
execve("./a.out", ["./a.out"], [/* 39 vars */]) = 0
brk(0) = 0x186e000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3c3d4d8000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=123841, ...}) = 0
mmap(NULL, 123841, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f3c3d4b9000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\240\356\1\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1572232, ...}) = 0
mmap(NULL, 3680296, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f3c3cf37000
mprotect(0x7f3c3d0b1000, 2093056, PROT_NONE) = 0
mmap(0x7f3c3d2b0000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x179000) = 0x7f3c3d2b0000
mmap(0x7f3c3d2b5000, 18472, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f3c3d2b5000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3c3d4b8000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3c3d4b7000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f3c3d4b6000
arch_prctl(ARCH_SET_FS, 0x7f3c3d4b7700) = 0
mprotect(0x7f3c3d2b0000, 16384, PROT_READ) = 0
mprotect(0x600000, 4096, PROT_READ) = 0
mprotect(0x7f3c3d4da000, 4096, PROT_READ) = 0
munmap(0x7f3c3d4b9000, 123841) = 0
getpid() = 9376
exit_group(0) = ?


The numbers that are at the end of the lines are the System Call numbers and the beginning of the lines are the sys. call names. That is all...

Here is a basic process on GDB to see the Sys. Assemble codes executed with your C Program's "main" func..

There are the input strings to your terminal in sequence. Follow the order;


gcc demo.c // it compiles and gives a.out.
gdb a.out //it starts the debugger gdb.
break main //it puts a break point to your code's main function.
run //it runs the program up to main func.
disassemble //it gives the system assemble codes.


Here is the process overview from my terminal.


erogol@ubuntu:~/Desktop/01-um-getpid$ gcc demo.c
erogol@ubuntu:~/Desktop/01-um-getpid$ gdb a.out
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/erogol/Desktop/01-um-getpid/a.out...(no debugging symbols found)...done.
(gdb) break main
Breakpoint 1 at 0x4004f8
(gdb) run
Starting program: /home/erogol/Desktop/01-um-getpid/a.out

Breakpoint 1, 0x00000000004004f8 in main ()
(gdb) disassemble
Dump of assembler code for function main:
0x00000000004004f4 <+0>: push %rbp
0x00000000004004f5 <+1>: mov %rsp,%rbp
=> 0x00000000004004f8 <+4>: mov $0x0,%eax
0x00000000004004fd <+9>: callq 0x400400
0x0000000000400502 <+14>: mov $0x0,%eax
0x0000000000400507 <+19>: leaveq
0x0000000000400508 <+20>: retq
End of assembler dump.
(gdb) ^CQuit
(gdb)

About OS!!!!

I just start a new course about Operating Systems concept so after a long time there will be some useful content in the blog about OS for sure!!! Keep up with me