Wednesday, January 16, 2013

The easiest way to retrieve data from a database and present them to web users on Java EE Platform

If your aim is to just retrieve information from a database and then present them to a web user on Java EE platform, probably the easiest way is to use Java Server Pages (JSP) and JSP Standard Tag Library (JSTL) technologies. JSP is a web component model. It heavily uses  HTML, CSS, Javascript technologies to present the model to the web user. JSP is a presentation technology. In design time it is basically an HTML file. Though you can insert any java scriptlet. All JSP components are translated in run-time to a Servlet class and then the translated java codes are compiled into bytecodes by the web container . This process is done when the JSP page is requested for the first time. It is possible to tell the web container to do the translation and compilation during the deployment in order to enhance the response time . JSPs and Servlets are different components in design-time, the same component in run-time. JSP pages are dynamic while Servlets are static components. Whenever you make a change in JSP page, the web container detects the change and re-translate and re-compile the page into bytecode ready to be run on JVM.   

MVC is an architectural design pattern used in both desktop and web applications. Due to its distributed nature, implementation of MVC pattern in web applications is somewhat different from the one used in desktop applications. For example any model update does not directly reflect to the web page in the client machine. It requires a request-response cycle. So observer pattern is not used in traditional web applications. Observer pattern in web applications is usually implemented by employing Ajax-push technology or by using Web sockets of HTML 5. Model in MVC is implemented by JavaBeans component model.

The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications. One of these functionalities is found in sql tag library: 
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>     
In order to use this tag library, first you must define a a data source (connection pool). In our example, we use MySQL database server: 
<sql:setDataSource driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/world"
                   user="root" password="root"/>
Using a connection from the connection pool, we can send a valid SQL statement to the server:
<sql:query var="continents">
   SELECT DISTINCT CONTINENT FROM COUNTRY
</sql:query>
The result set is stored in the variable continents.  Another example is given below:
<c:if test="${not empty param.continent}">
   <sql:query var="countries">
     SELECT * FROM COUNTRY WHERE continent= '${param.continent}'
   </sql:query>
</c:if>
where the result set stored in the variable countries contains countries in the selected continent ${param.continent}.
In the sample application we ask for a continent from the user. User selects the continent and then press the List button. The page displays the countries in the selected continent.  The complete solution is given in the following Jsp code, index.jsp:   

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<sql:setDataSource driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/world"
                   user="root"
                   password="root"/>
<sql:query var="continents">
    SELECT DISTINCT CONTINENT FROM COUNTRY
</sql:query>
<c:if test="${not empty param.continent}">
    <sql:query var="countries">
        SELECT * FROM COUNTRY WHERE continent= '${param.continent}'
    </sql:query>  
</c:if>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>World Countries</title>
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <style>
            tr.zebraHover { background-color: #FFFACD; }
            tr.striped_even { background-color:  #EFEFEF}
            tr.striped_odd { background-color:  #DFDFDF}            
        </style>
        <script type="text/javascript">
            $(document).ready(
            function () {
                $('tbody tr:even').mouseover(function(){
                    $(this).addClass('zebraHover');
                    $(this).removeClass('striped_even');
                });
                $('tbody tr:even').mouseout(function(){
                    $(this).removeClass('zebraHover');
                    $(this).addClass('striped_even');
                });
                $('tbody tr:odd').mouseover(function(){
                    $(this).addClass('zebraHover');
                    $(this).removeClass('striped_odd');
                });
                $('tbody tr:odd').mouseout(function(){
                    $(this).removeClass('zebraHover');
                    $(this).addClass('striped_odd');
                });
                $('tbody tr:odd').addClass('striped_odd');
                $('tbody tr:even').addClass('striped_even');
            }
            );
        </script>
    </head>
    <body>
        <form action="index.jsp" method="POST">
            <select name="continent">
                <c:forEach items="${continents.rows}" var="row">
                    <option value="${row.continent}">${row.continent}</option>
                </c:forEach>
            </select>
            <input type="submit" value="List"/>
            <br/>
            <c:if test="${not empty countries}">
                <table border="0">
                    <thead>
                    <tr>
                        <c:forEach items="${countries.columnNames}" var="headerName">
                            <th>${headerName}</th>
                        </c:forEach> 
                    </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${countries.rows}" var="row">
                            <tr>
                                <c:forEach items="${countries.columnNames}" var="columnName">
                                    <td>${row[columnName]}</td>
                                </c:forEach>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>    
            </c:if> 
        </form>
    </body>
</html>
The solution contains jQuery to add zebra effect to the table. You can download jQuery from http://www.jquery.comSample screen shots are given below:


You can download world database following the link. You can read the pdf to learn how to install MySQL and the world database. Changing this solution to Ajax-based application is simple. First we partition index.jsp into search.jsp and countries.jsp. Second, we add jquery code which sends the request asynchronously and makes partial update when the response is received:
 $('#listButton').click(function(){
     var continent= $('#selectContinent').val();
     $.ajax({
         method: "GET",
         url: "countries.jsp",
         data: "continent="+continent,
         success: function(responseData){
             $('#result').fadeOut('fast');
             $('#result').html(responseData).fadeIn('slow');
         }   
     });
  });

countries.jsp sends only the table containing the countries in the selected continent.

search.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<sql:setDataSource driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/world"
                   user="root"
                   password="root"/>
<sql:query var="continents">
    SELECT DISTINCT CONTINENT FROM COUNTRY
</sql:query>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>World Countries</title>
        <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
        <style>
            tr.zebraHover { background-color: #FFFACD; }
            tr.striped_even { background-color:  #EFEFEF}
            tr.striped_odd { background-color:  #DFDFDF}            
        </style>
        <script type="text/javascript">
            $(document).ready(
            function () {
                $('tbody tr:even').mouseover(function(){
                    $(this).addClass('zebraHover');
                    $(this).removeClass('striped_even');
                });
                $('tbody tr:even').mouseout(function(){
                    $(this).removeClass('zebraHover');
                    $(this).addClass('striped_even');
                });
                $('tbody tr:odd').mouseover(function(){
                    $(this).addClass('zebraHover');
                    $(this).removeClass('striped_odd');
                });
                $('tbody tr:odd').mouseout(function(){
                    $(this).removeClass('zebraHover');
                    $(this).addClass('striped_odd');
                });
                $('tbody tr:odd').addClass('striped_odd');
                $('#result table tbody tr:even').addClass('striped_even');
                $('#listButton').click(function(){
                    var continent= $('#selectContinent').val();
                    $.ajax({
                        method: "GET",
                        url: "countries.jsp",
                        data: "continent="+continent,
                        success: function(responseData){
                            $('#result').fadeOut('fast');
                            $('#result').html(responseData).fadeIn('slow');
                        }   
                    });
                });
            }
        );
        </script>
    </head>
    <body>
        <select id="selectContinent" name="continent">
            <c:forEach items="${continents.rows}" var="row">
                <option value="${row.continent}">${row.continent}</option>
            </c:forEach>
        </select>
        <input id="listButton" type="submit" value="List"/>
        <div id="result">

        </div>
    </body>
</html>

countries.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<sql:setDataSource driver="com.mysql.jdbc.Driver"
                   url="jdbc:mysql://localhost:3306/world"
                   user="root"
                   password="root"/>
<c:if test="${not empty param.continent}">
    <sql:query var="countries">
        SELECT * FROM COUNTRY WHERE continent= '${param.continent}'
    </sql:query>  
</c:if>
<c:if test="${not empty countries}">
    <table border="0">
        <thead>
            <tr>
        <c:forEach items="${countries.columnNames}" var="headerName">
            <th>${headerName}</th>
        </c:forEach> 
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${countries.rows}" var="row">
            <tr>
            <c:forEach items="${countries.columnNames}" var="columnName">
                <td>${row[columnName]}</td>
            </c:forEach>
            </tr>
        </c:forEach>
        </tbody>
    </table>    
</c:if> 

Thursday, January 10, 2013

How to change processor affinity in Windows and Linux

We have been playing multiple core processor systems for a long time. It is good to know that there are several cores available to run so many processes and threads in your system. The operating system is responsible how the processes are assigned to the cores. Usually you do not care how this process works. Actually modern operating system kernels are really successful to evenly distribute the load among the cores and can sometimes even migrate a thread or a process from one core to another if it is required. But sometimes you need to control or restrict the threads of a process to a subset of the cores. In Windows operating system you can easily restrict the threads to run on specific CPU's by using start command available since Windows XP.
Let's take a look at the start command line parameters:

s>start /?
Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
      [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
      [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
      [command/program] [parameters]

    "title"     Title to display in window title bar.
    path        Starting directory.
    B           Start application without creating a new window. The
                application has ^C handling ignored. Unless the application
                enables ^C processing, ^Break is the only way to interrupt
                the application.
    I           The new environment will be the original environment passed
                to the cmd.exe and not the current environment.
    MIN         Start window minimized.
    MAX         Start window maximized.
    SEPARATE    Start 16-bit Windows program in separate memory space.
    SHARED      Start 16-bit Windows program in shared memory space.
    LOW         Start application in the IDLE priority class.
    NORMAL      Start application in the NORMAL priority class.
    HIGH        Start application in the HIGH priority class.
    REALTIME    Start application in the REALTIME priority class.

    ABOVENORMAL Start application in the ABOVENORMAL priority class.
    BELOWNORMAL Start application in the BELOWNORMAL priority class.
    NODE        Specifies the preferred Non-Uniform Memory Architecture (NUMA)
                node as a decimal integer.
    AFFINITY    Specifies the processor affinity mask as a hexadecimal number.
                The process is restricted to running on these processors.

                The affinity mask is interpreted differently when /AFFINITY and
                /NODE are combined.  Specify the affinity mask as if the NUMA
                node's processor mask is right shifted to begin at bit zero.
                The process is restricted to running on those processors in
                common between the specified affinity mask and the NUMA node.
                If no processors are in common, the process is restricted to
                running on the specified NUMA node.
    WAIT        Start application and wait for it to terminate.
    command/program
                If it is an internal cmd command or a batch file then
                the command processor is run with the /K switch to cmd.exe.
                This means that the window will remain after the command
                has been run.

                If it is not an internal cmd command or batch file then
                it is a program and will run as either a windowed application

                or a console application.

    parameters  These are the parameters passed to the command/program.

NOTE: The SEPARATE and SHARED options are not supported on 64-bit platforms.

Specifying /NODE allows processes to be created in a way that leverages memory
locality on NUMA systems.  For example, two processes that communicate with
each other heavily through shared memory can be created to share the same
preferred NUMA node in order to minimize memory latencies.  They allocate
memory from the same NUMA node when possible, and they are free to run on
processors outside the specified node.

    start /NODE 1 application1.exe
    start /NODE 1 application2.exe

These two processes can be further constrained to run on specific processors
within the same NUMA node.  In the following example, application1 runs on the
low-order two processors of the node, while application2 runs on the next two
processors of the node.  This example assumes the specified node has at least
four logical processors.  Note that the node number can be changed to any valid
node number for that computer without having to change the affinity mask.

    start /NODE 1 /AFFINITY 0x3 application1.exe
    start /NODE 1 /AFFINITY 0xc application2.exe


If Command Extensions are enabled, external command invocation
through the command line or the START command changes as follows:

non-executable files may be invoked through their file association just

    by typing the name of the file as a command.  (e.g.  WORD.DOC would
    launch the application associated with the .DOC file extension).
    See the ASSOC and FTYPE commands for how to create these
    associations from within a command script.

When executing an application that is a 32-bit GUI application, CMD.EXE

    does not wait for the application to terminate before returning to
    the command prompt.  This new behavior does NOT occur if executing
    within a command script.

When executing a command line whose first token is the string "CMD "

    without an extension or path qualifier, then "CMD" is replaced with
    the value of the COMSPEC variable.  This prevents picking up CMD.EXE
    from the current directory.

When executing a command line whose first token does NOT contain an

    extension, then CMD.EXE uses the value of the PATHEXT
    environment variable to determine which extensions to look for
    and in what order.  The default value for the PATHEXT variable
    is:

        .COM;.EXE;.BAT;.CMD


    Notice the syntax is the same as the PATH variable, with

    semicolons separating the different elements.

When searching for an executable, if there is no match on any extension, then looks to see if the name matches a directory name.  If it does, the START command launches the Explorer on that path.  If done from the command line, it is the equivalent to doing a CD /D to that path.

The option affinity is the one we are interested in.  This option takes one parameter which instructs the process scheduler that the process threads run only on the selected subset of the cores. The parameter is an integer given in base 16. For 2-core hyper-thread cpu, operating systems senses 4 logical CPU's and let's denote them as CPU0, CPU1, CPU2 and CPU3. In the table given below, you can easily follow how the parameter controls which cores are used:

Parameter CPU3 CPU2 CPU1 CPU0
0x01 - - - +
0x02 - - + -
0x03 - - + +
0x04 - + - -
0x05 - + - +
0x06 - + + -
0x07 - + + +
0x08 + - - -
0x09 + - - +
0x0A + - + -
0x0B + - + +
0x0C + + - -
0x0D + + - +
0x0E + + + -
0x0F + + + +

where + means the corresponding CPU is used, and - means the corresponding CPU is NOT used in the scheduling. To verify that the start command with its options is working properly, i have written the following very simple java code:



package com.example.console;

public class TestCpuAffinity {
    public static void main(String[] args) {
    System.err.println("Number of available processor: "+Runtime.getRuntime().availableProcessors()); 
    }
}


The code simply prints the number of cores available out to the console. Here are the results:

start /affinity 0xF "running" /B java com.example.console.TestCpuAffinity
Number of available processors: 4

start /affinity 0xA "running" /B java com.example.console.TestCpuAffinity
Number of available processors: 2

start /affinity 0x1 "running" /B java com.example.console.TestCpuAffinity
Number of available processors: 1

start /affinity 0x2 "running" /B java com.example.console.TestCpuAffinity
Number of available processors: 1

start /affinity 0x3 "running" /B java com.example.console.TestCpuAffinity
Number of available processors: 2

It is easy to do the same thing in Linux with the help of taskset command which is basically use the same mask defined in Windows. The manual page of taskset is given below:


TASKSET(1)                    Linux User’s Manual                   TASKSET(1)

NAME
       taskset - retrieve or set a process’s CPU affinity

SYNOPSIS
       taskset [options] mask command [arg]...
       taskset [options] -p [mask] pid

DESCRIPTION
       taskset  is  used  to  set  or retrieve the CPU affinity of a running process given its PID or to launch a new COMMAND with a given CPU affinity.  CPU affinity is a scheduler property that "bonds" a process to a given set of CPUs on the system.  The Linux scheduler  will honor  the  given CPU affinity and the process will not run on any other CPUs.  Note that the Linux scheduler also supports natural CPU affinity: the scheduler attempts to keep processes on the same CPU as long as practical for performance reasons.  Therefore, forcing  a specific CPU affinity is useful only in certain applications.

       The  CPU  affinity  is represented as a bitmask, with the lowest order bit corresponding to the first logical CPU and the highest order bit corresponding to the last logical CPU.  Not all CPUs may exist on a given system but a mask may specify more CPUs than are present.
       A  retrieved  mask will reflect only the bits that correspond to CPUs physically on the system.  If an invalid mask is given (i.e., one that corresponds to no valid CPUs on the current system) an error is returned.  The masks are  typically  given  in  hexadecimal. For example,

       0x00000001
              is processor #0

       0x00000003
              is processors #0 and #1

       0xFFFFFFFF
              is all processors (#0 through #31)

       When taskset returns, it is guaranteed that the given program has been scheduled to a legal CPU.

OPTIONS
       -p, --pid
              operate on an existing PID and not launch a new task

       -c, --cpu-list
              specify  a  numerical  list  of  processors  instead of a bitmask.  The list may contain multiple items, separated by comma, and
              ranges.  For example, 0,5,7,9-11.

       -h, --help
              display usage information and exit

       -V, --version
              output version information and exit

USAGE
       The default behavior is to run a new command with a given affinity mask:
              taskset mask command [arguments]

       You can also retrieve the CPU affinity of an existing task:
              taskset -p pid

       Or set it:
              taskset -p mask pid

Here is the sample usage of taskset command on running firefox:

[root@server1 ~]# taskset -c 1 firefox &
[1] 1032
[root@server1 ~]# taskset -p 1032
pid 1032's current affinity mask: 2




Sunday, January 6, 2013

MD-2012-IV

Matematik dünyası dergisinin 2012-IV sayısı çıktı. Abone olmak için bağlantıyı takip edin. Yeni sayının içeriğine buradan bakabilirsiniz. MD-2012-IV sayısının giriş yazısını aşağıda alıntıladım:
Gün geçmez ki bir gazeteci ya da televizyoncu bana eğitimde neden bu halde olduğumuzu sormasın.
Söylenecek o kadar çok şey var ki hangi birini söyleyeceğimi şaşırırım.
Baktım yanlışlarla başa çıkamıyorum, yöntem değiştirdim, doğruları bulayım bari dedim.
 İnanır mısınız bir tane doğru bulamadım.
Her şeyi değiştirin ama eğitimimizin şu özelliğine ne olur dokunmayın diyebileceğim tek bir husus bile yok. 
Bunun ancak tek bir anlamı olabilir: Eğitim sistemimiz reformla filan düzenlenebilecek durumda değildir. Kökten değişmeli. Yönetmeliklerle filan yetinmeyip tüm eğitim anlayışımızı, felsefemizi, eğitime bakışımızı, eğitimle ilgili her şeyimizi sorgulamalı ve tepeden tırnağa değiştirmeliyiz. Kısacası eğitim sistemimizde reform değil devrim yapmalıyız. Başka türlü bu eğitim sistemi düzelmez.
Okul binalarına bir göz atın. Okul binaları okuldan çok bir hapishaneyi andırmıyor mu? Böyle okullarda doğru eğitim yapılabilir mi?  Böyle okullara öğrenciler koşa koşa, güle oynaya gidebilirler mi? Mümkün mü? 
Matematik Köyü'nü kurmadan önce izin için çırpınıp dururken Milli Eğitim Müdürlüğü'ne gittik. Bize iki tip okul binası gösterdiler. İki türden biri olmalıymış!
Daha neler! Müdürlükten nasıl kaçtığımı bilmiyorum. Şirince'deki ilköğretim okulu bildiğimiz standart okullardan, bir beton yığını. Bahçesi bile. Hemen yanında da eski bir Rum binasından devşirme bir meyhane vardır. Yüksek tavanlı, iki katlı taş bir bina. Olağanüstü güzel. Kocaman bahçesinde devasa çam ağaçları yükselir. Meğer bu meyhane Rumlar zamanında köyün okuluymuş. Mübadeleden sonra ilkokulu bozup meyhane yapmışlar. okul niyetine de bildiğimiz ucube binalardan birini yapmışlar!
Galiba eğitim sistemimizi değiştirmeden önce ar duygumuzu geliştirmeliyiz! 
Ama yuvalara ve kreşlere dikkat ettiniz mi, ne kadar sevimliler. Rengarenk, davetkar, iç açıcı, kucaklayıcı, güven verici. Çünkü okul öncesi eğitim zorunlu olmadığından onlara karışmıyorlar!
Ah! İşte çözüm! Çözümü bulduk. Karışma! Serbest bırak!
Popülizmin tuzağına düşüp halkımız en iyisini bilir demeyeyim de, belli ki yetkililerden daha iyisini biliyor. Çoğu şey gibi eğitim de rekabete açık olsun. Başarılı okulları, öğretmenleri, binaları ödüllendir. Müfettişe bile ihtiyacınız kalmaz! 
Şu bir gerçek ki devlet yapısı hantal. Belki de öyle olmalı, bilmiyorum. Oysa toplum, teknoloji ve bilim çok çabuk değişiyor artık. Eğitimin de bu değişime ayak uydurması lazım. Devletin hantal yapısı yüzünden eğitim değişime ve ihtiyaçlara ayak uyduramıyor. 
Bir gün bu düşünceyi savunabileceğim aklıma bile gelmezdi.    
Ama akıl ve mantık bunu gerektiriyor. Karşı koymanın anlamı yok.
Ali Nesin

Saturday, December 1, 2012

SEMBOL TABLOSU

C ya da C++'de geliştirdiğimiz uygulamalarda hata ayıklama yapmamız gerektiğinde, kodu GNU c derleyeyicisi ile -g seçeneği ile derlememiz gerekir. Aksi halde gdb ile uygulamada hata ayıklamak istediğimizde sembol tablosunu bulamadığına ilişkin uyarı verecektir:
[guru@godel ~]$ g++ -o lottery lottery.cpp -std=c++11
[guru@godel ~]$ gdb lottery 
GNU gdb (GDB) Fedora (7.4.50.20120120-42.fc17)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/guru/lottery...(no debugging symbols found)...done.
(gdb) quit
[guru@godel ~]$ g++ -g -o lottery lottery.cpp -std=c++11
[guru@godel ~]$ gdb lottery 
GNU gdb (GDB) Fedora (7.4.50.20120120-42.fc17)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/guru/lottery...done.

lottery.cpp: Sayısal loto için 6 adet [1,49] aralığında birbirinden farklı sıralı sayı üretir

#include <iostream>
#include <algorithm>
#include <random>
#include <list>

using namespace std;

int main(){
   random_device rd; 
   mt19937 gen(rd());
   uniform_int_distribution<uint32_t> dist(1,49);
   list<uint32_t> lst;
   while ( lst.size() < 6 ){
      uint32_t r;
      do {
        r= dist(gen);
      } while(find(lst.begin(),lst.end(),r)!=lst.end());
      lst.push_front(r);
   }   
   lst.sort();
   for (auto x : lst)
       cout <<  x << endl;
   return 0;
}

-g seçeneği ile derlendiğinde çalıştırılabilir dosyanın içinde sembol tablosu da yer alacaktır. Hata ayıklayıcı sembol tablosunu, kod ile bellek alanlarını eşleştirmek için kullanmaktadır. Ancak bunun bir yan etkisi bulunmaktadır. Sembol tablosu çalıştırılabilir dosyanın içinde yer aldığı için dosyanın boyu büyümektedir. İstenirse sembol tablosunu çalıştırılabilir dosyanın dışına ayrı bir dosyaya alınabilir. Bunun için strip ve objcopy komutlarından yararlanıyoruz.
[guru@godel ~]$ objcopy --only-keep-debug lottery lottery.debug
[guru@godel ~]$ strip --strip-debug --strip-unneeded lottery
[guru@godel ~]$ objcopy --add-gnu-debuglink=lottery.debug lottery
[guru@godel ~]$ ls -lh lottery*
-rwxrwxr-x. 1 student student 17K Dec  1 16:05 lottery
-rw-rw-r--. 1 student student 506 Dec  1 15:50 lottery.cpp
-rwxrwxr-x. 1 student student 77K Dec  1 16:04 lottery.debug
[guru@godel ~]$ gdb lottery
GNU gdb (GDB) Fedora (7.4.50.20120120-42.fc17)
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/guru/lottery...Reading symbols from /home/guru/lottery.debug...done.
(gdb) list 1,10
1 #include <iostream>
2 #include <algorithm>
3 #include <random>
4 #include <list>
5
6 using namespace std;
7
8 int main(){
9   random_device rd;
10   mt19937 gen(rd());
(gdb) list 11,20
11   uniform_int_distribution<uint32_t> dist(1,49);
12   list<uint32_t> lst;
13   while ( lst.size() < 6 ){
14      uint32_t r;
15      do {
16        r= dist(gen);
17      } while(find(lst.begin(),lst.end(),r)!=lst.end()) ;
18      numbers.push_front(r);
19   }
20   lst.sort();
(gdb) break 13
Breakpoint 1 at 0x401019: file lottery.cpp, line 13.
(gdb) break 20
Breakpoint 2 at 0x4010d2: file lottery.cpp, line 20.
(gdb) info breakpoints
Num     Type           Disp Enb Address            What
1       breakpoint     keep y   0x0000000000401019 in main() at lottery.cpp:13
2       breakpoint     keep y   0x00000000004010d2 in main() at lottery.cpp:20
(gdb) run
Starting program: /home/guru/lottery 

Breakpoint 1, main () at lottery.cpp:13
13   while ( lst.size() < 6 ){
(gdb) print lst
$1 = empty std::list
(gdb) cont
Continuing.

Breakpoint 2, main () at lottery.cpp:20
20   lst.sort();
(gdb) print lst
$2 = std::list = {[0] = 23, [1] = 42, [2] = 7, [3] = 22, [4] = 21, [5] = 36}
(gdb) cont
Continuing.
7
21
22
23
36
42
[Inferior 1 (process 2463) exited normally]
(gdb) quit


Solaris11'de NFS Paylaşımı Tanımlama ve Windows 7'den Erişim

ZFS, Sun Microsystems firmasında Jeff Bonwick ve Matthew Atrens'in başını çektiği bir ekip tarafından tarafından geliştirilmiş hem bir dosya hem de LVM (Logical Volume Management) sistemini içeren bir teknolojidir. Başlangıçta açık kaynak kodlu bir proje olarak Common Development and Distribution License modeli ile geliştirilen sistem artık Oracle firmasının ticari bir ürünüdür. Solaris 11 işletim sisteminin en önemli bileşenlerinden biri olarak öne çıkmaktadır. 

ZFS ile 278 sekizliği adreslemek mümkündür. Bu şimdilik teorik olarak ulaşılabilecek üst değeri ifade ediyor ve çok uzun süre ihtiyaçlarımızı karşılayacaktır. ZFS elbette bu kapasitenin ötesinde farklı yetenekler sunuyor. Bu yeteneklerden birkaç tanesi aşağıda sıralanmıştır:
  • Anlık yedek oluşturabilme, 
  • Kolay kurulum ve yönetim, 
  • Şifreleme, 
  • Sessiz onarım, 
  • Değişken blok boyutu tanımlayabilme, 
  • Little-endian/big-endian farklı sistemler arasında sorunsuz dosya sistemi aktarımı
Bu yazıda zfs üzerinde NFS tipinde bir dosya sisteminin nasıl yaratılacağı ve bu paylaşılan alana Windows 7'den nasıl erişilebileceği anlatılacaktır. İşleme shared isimli bir bölüm yaratarak başlıyoruz. Ardından bu bölüm nfs olarak tanımlanıyor ve paylaşıma açılıyor:

#zfs create rpool/shared
#zfs set share=name=shared,path=/rpool/shared,prot=nfs rpool/shared
name=shared,path=/rpool/shared,prot=nfs,public=true,sec=sys,rw=*
#zfs set sharenfs=on rpool/shared
#cat /etc/dfs/sharetab
/rpool/shared    shared    nfs     sec=sys,rw

Sistemin çalışabilmesi için NFS servisini açmak gerekir:
#svcadm enable svc:/network/nfs/server:default

Windows 7'ye Solaris 11'de paylaşıma açılan NFS bölümünü tanıtmak için öncelikle Windows'da NFS Client özelliğini açmak gerekir. Bunun için ilk olarak Control Panel'den Programs and Features seçilir:


Çıkan pencerede Turn Windows features on or off bağlantısı seçilir:


Çıkan diyalog kutusunda Services for NFS seçilir:


Windows yeniden başlatıldıktan sonra komut satırından mount komutu çalıştırılır: 

C:\Users\godel>showmount -e 192.168.1.3
Exports list on 192.168.1.3:
/rpool/shared                      All Machines

C:\Users\godel>mount -o mtype=hard 192.168.1.3:/rpool/shared z:
z: is now successfully connected to 192.168.1.3:/rpool/shared

The command completed successfully.