tag:blogger.com,1999:blog-7771826239054301662024-03-19T04:26:51.910-07:00Sistemas Soperativos.
.collihttp://www.blogger.com/profile/03958651874427482292noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-777182623905430166.post-69681437905742499472012-05-20T23:54:00.001-07:002012-09-20T15:04:48.822-07:00Locks<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://d24w6bsrhbeh9d.cloudfront.net/photo/4100321_700b_v1.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="516" src="http://d24w6bsrhbeh9d.cloudfront.net/photo/4100321_700b_v1.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div class="separator" style="clear: both; text-align: center;">
<br /></div>
Imagen de http://<b>9gag</b>.com/gag/4100321<br />
<br /></td></tr>
</tbody></table>
<b><span style="font-size: large;"><span style="background-color: black;"><span style="color: lime;">Formato de la tarea:</span></span></span></b>
<br />
<ul>
<li>Tomar una foto a los pasos <b>4 </b>y<b> 5</b> como se muestra en el ejemplo</li>
<li>Ponerlas en formato <b>pdf</b></li>
<li>Enviarlas al correo electronico: <b>sistemas.operativos.fime@gmail.com</b></li>
<li>Asunto: <b>HORA</b> - Tarea 4 - Matricula - Nombre</li>
<li>Entregarla <b>antes</b> del <b>jueves 23 de mayo</b></li>
</ul>
<b><span style="color: red;">Correo que no tenga el formato correcto NO sera revisada.</span></b><br />
<ul>
</ul>
<div>
<a name='more'></a><br />
<b>1.- Implementar Locks en NachOS</b><br />
<b><br /></b>
Bueno lo primero que tenemos que hacer es abrir nuestra terminal y ir a nuestra carpeta de threads<b><br /></b><br />
<br />
<blockquote class="tr_bq">
cd nachos/nachos/code/threads</blockquote>
<br />
Bueno para la implementación de los <b>Locks</b> editaremos los archivos <b>synch.cc </b>y<b> synch.h</b>.<br />
<br />
<blockquote>
sudo gedit synch.h</blockquote>
<br />
<br />
Buscamos la linea 89 y depues de donde dice:<br />
<br />
<pre class="brush: cpp"> private:
const char* name; // para depuraci�n
</pre>
Agregaremos <i>Semaphore semaforo;</i>
<br />
<pre class="brush: cpp"> private:
const char* name; // para depuraci�n
Semaphore semaforo;
</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-qUSmAzK8bLE/T7nxcbeylpI/AAAAAAAAAPk/yRSIoNkwdAc/s1600/synch.h.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="610" src="http://2.bp.blogspot.com/-qUSmAzK8bLE/T7nxcbeylpI/AAAAAAAAAPk/yRSIoNkwdAc/s640/synch.h.png" width="640" /></a></div>
<br />
Ahora editaremos el <b>synch.cc</b>
<br />
<blockquote>
sudo gedit synch.cc</blockquote>
Al principio agregamos:<br />
<pre class="brush: cpp">#include <iostream>
</pre>
<br />
Buscamos donde viene <b>Locks</b> debe verse algo asi
<br />
<pre class="brush: cpp">// Dummy functions -- so we can compile our later assignments
// Note -- without a correct implementation of Condition::Wait(),
// the test case in the network assignment won't work!
Lock::Lock(const char* debugName) {}
Lock::~Lock() {}
void Lock::Acquire() {}
void Lock::Release() {}
</pre>
<br />
Una vez que implementamos los <b>Locks</b> deberia verse asi:
<br />
<pre class="brush: cpp">Lock::Lock(const char* debugName)
:name(debugName), semaforo("semaforo_lock", 1) //constructor
{
printf("lock constructor\n");
}
Lock::~Lock()
{
printf("lock destructor \n");//destructor
}
void Lock::Acquire() {
semaforo.P();
printf("acquiring lock\n"); //debugging purposes
}
void Lock::Release() {
semaforo.V();
printf("releasing lock\n"); //debugging purposes
}
</pre>
<br />
<a href="http://1.bp.blogspot.com/-Rx9FZWiu9Lc/T7nxbV47xhI/AAAAAAAAAPc/moe7jf-DYVU/s1600/synch.cc.png" imageanchor="1" style="font-size: 13px; margin-left: 1em; margin-right: 1em; text-align: center;"><img border="0" height="614" src="http://1.bp.blogspot.com/-Rx9FZWiu9Lc/T7nxbV47xhI/AAAAAAAAAPc/moe7jf-DYVU/s640/synch.cc.png" width="640" /></a><br />
<b>2.- Crear un programa que corra Locks</b><br />
<br />
Bueno para esto abriremos el archivo <b>threadtest.cc</b>.<br />
<br />
<blockquote class="tr_bq">
sudo gedit threadtest.cc</blockquote>
Lo primero que tenemos que agregar son las librerias nuevas
<br />
<pre class="brush: cpp">#include "synch.h" //agregado para ejecutar los locks
#include <iostream>
using namespace std;
#include <ctime>
#include <cstdlib></pre>
<br />
Ahora antes de:
<br />
<pre class="brush: cpp">void
SimpleThread(void* name)
{
// Reinterpret arg "name" as a string
char* threadName = (char*)name;
// If the lines dealing with interrupts are commented,
// the code will behave incorrectly, because
// printf execution may cause race conditions.
for (int num = 0; num < 10; num++) {
//IntStatus oldLevel = interrupt->SetLevel(IntOff);
printf("*** thread %s looped %d times\n", threadName, num);
//interrupt->SetLevel(oldLevel);
//currentThread->Yield();
}
//IntStatus oldLevel = interrupt->SetLevel(IntOff);
printf(">>> Thread %s has finished\n", threadName);
//interrupt->SetLevel(oldLevel);
}
</pre>
<br />
Agregaremos los Siguientes codigos:
<br />
<br />
Codigo del Productor Consumidor<br />
<pre class="brush: cpp">//apuntador a un lock compartido en todo el codigo
Lock *l;
Lock *l2; //lock usado para crear un deadlock
Lock *l3; //lock usado para crear un deadlock
Lock *consumidor; //usado para bloquear a los consumidores
Lock *productor; //usado para bloquear a los productores
Lock *modificarComestibles; //exclusion mutua entre productores y consumidores
int comestibles;
int maxComestibles;
//se ejecuta la rutina para los consumidores
void
Consumidor(void *name){
char* threadName = (char*)name;
bool tieneLock = false;
while(1){
if(!tieneLock){
consumidor->Acquire();
tieneLock = true;
}
cout <<"comestibles: "<<comestibles << "\n";
if(comestibles > 0){ //podemos consumir productos
//parte critica del codigo que se comparte entre todos los threads
//sean productores o consumidores
modificarComestibles->Acquire();
comestibles --;
modificarComestibles->Release();
cout<<threadName<<" consumio\n";
consumidor->Release();
tieneLock = false;
}else{
cout <<threadName <<" no puede consumir \n";
}
currentThread->Yield();
}
}
//se ejecuta la rutina para los productores
void
Productor(void* name){
char* threadName = (char*)name;
//cout <<"\nrutina del productor\n";
bool tieneLock = false;
while(1){
if(!tieneLock){
productor->Acquire();
tieneLock = true;
}
cout <<"comestibles: "<<comestibles << "\n";
if(comestibles < maxComestibles){ //podemos producir
//parte critica del codigo que se comparte entre todos los threads
//sean productores o consumidores
modificarComestibles -> Acquire();
comestibles ++;
modificarComestibles -> Release();
cout<<threadName<<" produjo\n";
productor->Release();
tieneLock = false;
}else{
cout <<threadName <<" no puede producir \n";
}
currentThread->Yield();
}
}
</pre>
<br />
Prueba Fairness.<br />
<pre class="brush: cpp">void
PruebaFairness(void* name){
//parseando de tipo void a tipo char
char* threadName = (char*)name;
cout << "ejecutando Fairness para thread "<< threadName << "\n";
int repeticiones = 3;
while(repeticiones >= 0 ){
cout << threadName <<" quiere el lock\n";
l->Acquire();
cout << threadName <<" tiene el lock\n";
l->Release();
repeticiones--;
currentThread->Yield(); //despierta el primer thread en la cola
// currentThread->Sleep();//manda el thread al final de la cola
}
}
</pre>
Prueba Liveness.<br />
<pre class="brush: cpp">void
PruebaLiveness(void* name){
char* threadName = (char*)name;
srand(time(0));
float probabilidad;
float pasa = 0.5;
int a;
int repeticiones = 0;
while(repeticiones < 3){
probabilidad = (float)rand()/RAND_MAX ;
if (probabilidad > pasa){
cout << threadName << " pide el lock\n";
l->Acquire();
cout << threadName << " tiene el lock\n";
for (int i = 0; i< 10000; i++){
a++;
}
for (int i = 0; i< 10000; i++){
a--;
}
l->Release();
cout << threadName << " libera el lock\n";
//cout << probabilidad<<endl;
}
currentThread->Yield();
repeticiones++;
}
}
</pre>
<br />
Prueba Safety (con esta aremos un deadlock).<br />
<pre class="brush: cpp">void
DeadLock1(void* name){
char* threadName = (char*)name;
cout <<"\n"<<threadName <<" funciona de la siguiente manera\n";
cout <<"l2 Acquire()\n";
cout <<"l3 Acquire()\n";
cout <<"realiza operaciones criticas \n";
cout <<"l3 release()\n";
cout <<"l2 release()\n";
currentThread->Yield();
l2->Acquire();
cout <<"\n"<<threadName<<" Adquiere l2\n";
cout <<threadName<<" es interrumpido\n";
currentThread->Yield();
l3->Acquire();
cout<<"esta parte nunca va a pasar\n";
l3->Release();
l2->Release();
}
void
DeadLock2(void* name){
char* threadName = (char*)name;
cout <<"\n"<<threadName <<" funciona de la siguiente manera\n";
cout <<"l3 Acquire()\n";
cout <<"l2 Acquire()\n";
cout <<"realiza operaciones criticas \n";
cout <<"l2 release()\n";
cout <<"l3 release()\n";
currentThread->Yield();
l3->Acquire();
cout <<"\n"<<threadName<<" Adquiere l3\n";
cout <<threadName<<" es interrumpido\n";
currentThread->Yield();
l2->Acquire();
cout<<"esta parte nunca va a pasar\n";
l2->Release();
l3->Release();
}</pre>
<br />
Despues de Agregarlos buscamos el que dice <b>ThreadTest()</b> y en este agregaremos <span style="color: red;">/*</span> y <span style="color: red;">*/ </span>para que no ejecute el SimpleTest(), debe quedar como en la siguiente imagen.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-UWu4pBiUT1E/T7n56yZhnNI/AAAAAAAAAPw/SpWUNhnrmC8/s1600/coments.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="430" src="http://3.bp.blogspot.com/-UWu4pBiUT1E/T7n56yZhnNI/AAAAAAAAAPw/SpWUNhnrmC8/s640/coments.png" width="640" /></a></div>
<br />
Despues del <span style="color: red;"><b>*/</b></span> y <b>antes</b> de <span style="color: red;"><b>} </b></span>agregamos el siguiente codigo:<br />
<br />
<br />
<pre class="brush: cpp"> int n = 10;
int p = 3; //cuantos productores
int c = 2;// cuantos consumidores
l = new Lock("lock1");
l2 = new Lock("lock2");
l3 = new Lock("lock3");
modificarComestibles = new Lock("comestibles");//bloquea productores y consumidores
consumidor = new Lock("consumidor");//bloquea consumidores
productor = new Lock("productor");//bloquea productores
comestibles = 0; //cero comestibles
maxComestibles = 10; //maximo de productos que podemos tener en cola
cout << "*------------->Ejecutando prueba para Fairness<-------------*\n";
for ( int k=1; k<=n; k++) {
char* threadname = new char[100];
sprintf(threadname, "Hilo %d", k);
Thread* newThread = new Thread (threadname);
newThread->Fork (PruebaFairness, (void*)threadname);
}
PruebaFairness( (void*)"Hilo 0");
//se realiza la prueba de livenes "si varios threads piden un lock
//al mismo tiempo al menos uno lo debe de obtener"
cout << "\n*------------->Ejecutando prueba para Liveness<-------------*\n";
for ( int k=1; k<=n; k++) {
char* threadname = new char[100];
sprintf(threadname, "Hilo %d", k);
Thread* newThread = new Thread (threadname);
newThread->Fork (PruebaLiveness, (void*)threadname);
}
PruebaLiveness((void*)"Hilo 0");
// Productor((void*)"Productor0");
/*
cout << "\n*------------->Ejecutando prueba para Safety<-------------*\n";
for ( int k=1; k<=1; k++) {
char* threadname = new char[100];
sprintf(threadname, "Hilo %d", k);
Thread* newThread = new Thread (threadname);
newThread->Fork (DeadLock2, (void*)threadname);
}
DeadLock1((void*)"Hilo 0");
*/
cout <<"\n*------------->Ejecutando el programa del productor consumidor<-------------*\n";
cout << "\ncreando productores\n";
for ( int k=1; k<=p; k++) {
char* threadname = new char[100];
sprintf(threadname, "Productor %d", k);
Thread* newThread = new Thread (threadname);
newThread->Fork (Productor, (void*)threadname);
}
cout << "\ncreando consumidores\n";
for ( int k=2; k<=c; k++) {
char* threadname = new char[100];
sprintf(threadname, "Consumidor %d", k);
Thread* newThread = new Thread (threadname);
newThread->Fork (Consumidor, (void*)threadname);
}
Consumidor((void*)"Consumidor 1");
</pre>
<br />
<br />
<b>3.- Compilar</b>
<br />
Bueno aqui tecleamos en la terminal lo siguiente:
<br />
<blockquote>
cd ..</blockquote>
<br />
Y ahora si le damos <i>make</i>.
<br />
<blockquote>
make</blockquote>
<b>4.- Primera prueba correr nachOS. </b><br />
Suponiedo que no marco algun error volvemos a la carpeta de threads y para correrlo le tecleamos:</div>
<blockquote class="tr_bq">
cd threads</blockquote>
<div>
<br />
y lo corremos<br />
<br /></div>
<blockquote class="tr_bq">
./nachos</blockquote>
<div>
Esta prueba deberia correr <b>PruebaFairness</b>, <b>PruebaLiveness </b>y el <b>Consumidor </b>- <b>Productor</b>. La ejecución deberia verse de la siguiente manera:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://2.bp.blogspot.com/-Kg0kgOOBtIE/T7qhEFy32QI/AAAAAAAAAQM/dVkafL3JagA/s1600/productor-consumidor.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="432" src="http://2.bp.blogspot.com/-Kg0kgOOBtIE/T7qhEFy32QI/AAAAAAAAAQM/dVkafL3JagA/s640/productor-consumidor.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><b style="background-color: red;"><span style="color: white;">Imagen para la tarea.</span></b></td></tr>
</tbody></table>
<br />
<b>5.- Causar un DeadLock.</b><br />
<br />
Para matar el proceseso presionamos <b>Ctrl C</b>, y despues abrimos el archivo <b style="font-style: italic;">threadtest.cc </b>y borraremos el <span style="color: red;"><b>/*</b></span> y <span style="color: red;"><b>*/</b></span> del <b>DeadLock </b>como en la siguiente imagen:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-vLy4YithweQ/T7qhDEqPgmI/AAAAAAAAAQE/G3rhPSOyL_U/s1600/Lock+del+codigo.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="430" src="http://2.bp.blogspot.com/-vLy4YithweQ/T7qhDEqPgmI/AAAAAAAAAQE/G3rhPSOyL_U/s640/Lock+del+codigo.png" width="640" /></a></div>
<br />
<br />
Ahora lo siguiente es volver a compilar nachOS, tecleamos en la terminal lo siguiente:<br />
<blockquote>
cd ..</blockquote>
<br />
Y ahora si le damos <i>make</i>.<br />
<blockquote>
make</blockquote>
<b><br /></b>
Suponiedo que no marco algun error volvemos a la carpeta de threads y para correrlo le tecleamos:<br />
<blockquote>
cd threads</blockquote>
y lo corremos<br />
<blockquote>
./nachos<br />
<div>
<br /></div>
</blockquote>
Una vez que corremos nachOS deberia verse algo asi:<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://3.bp.blogspot.com/-3-_BJY3FFjo/T7qhB2t2tqI/AAAAAAAAAP8/mTSOrj1rHnE/s1600/LocK.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img alt="" border="0" height="413" src="http://3.bp.blogspot.com/-3-_BJY3FFjo/T7qhB2t2tqI/AAAAAAAAAP8/mTSOrj1rHnE/s640/LocK.png" title="" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td class="tr-caption" style="font-size: 13px;"><b style="background-color: red;"><span style="color: white;">Imagen para la tarea.</span></b></td></tr>
</tbody></table>
</td></tr>
</tbody></table>
<br />
<iframe allowfullscreen="allowfullscreen" frameborder="0" height="480" src="http://www.youtube.com/embed/rrVwdY-ZtUg" width="640"></iframe>
<br />
<br />
Informacion y codigos de:
http://sistemassoperativos.blogspot.mx/2011/09/first-practical-presentation.html</div>
Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-777182623905430166.post-42207984882334320212012-05-09T12:07:00.002-07:002012-05-09T16:00:18.598-07:00Hola Mundo en nachOSBueno la tarea ahora es crear un programa y ejecutarlo.
Formato de la tarea:
<br />
<ul>
<li>Tomar una foto a los pasos <b>2</b>, <b>3</b>, <b>4</b> y <b>6</b> como se muestra en el ejemplo</li>
<li>Ponerlas en formato <b>pdf</b></li>
<li>Enviarlas al correo electronico: <b>sistemas.operativos.fime@gmail.com</b></li>
<li>Ausnto: Tarea 3 - Matricula - Nombre</li>
<li>Entregarla antes del <b>miercoles 11 de mayo</b></li>
</ul>
<div>
<b></b><br />
<a name='more'></a></div>
Lo primero que tiene que hacer es abrir la terminal y teclear
<br />
<blockquote>
<code>cd /nachos/nachos/code/test </code></blockquote>
Pasos para crear y ejecutar el programa:
<br />
<b><br /></b><br />
<b>1.- Creamos el archivo holamundo, tecleando en la terminal</b>
<br />
<blockquote>
<code>sudo gedit holamundo.c</code></blockquote>
<b>2.- Escribimos el codigo del programa</b>
<br />
<blockquote>
<pre class="brush: cpp" width="100%">#include "syscall.h"
// Ejemplo de Holamundo
int main () {
Write("Hola Mundo! \n :B ",12,10);
Halt();
}</pre>
</blockquote>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-GbEi7iuIOK0/T6rHBHvDlYI/AAAAAAAAAOQ/TWbHrM5lhkY/s1600/paso2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="422" src="http://4.bp.blogspot.com/-GbEi7iuIOK0/T6rHBHvDlYI/AAAAAAAAAOQ/TWbHrM5lhkY/s640/paso2.png" width="640" /></a></div>
Se deberá ver como la siguiente imagen<br />
<div>
<b><br /></b><br />
<b>3.- Modificar el archivo Makefile</b></div>
<div>
Guardamos el archivo y tecleamos en la terminal:</div>
<blockquote>
<div>
<code>sudo gedit Makefile</code></div>
</blockquote>
<div>
Buscamos la linea que dice "all:" y agregamos nuestro programa</div>
<blockquote>
<pre class="brush: cpp" width="100%">all: halt shell matmult sort holamundo</pre>
</blockquote>
<div>
Abajo en el mismo archivo agregamos las siguientes lineas:</div>
<blockquote>
<pre class="brush: cpp" width="100%">holamundo.o: holamundo.c
$(CC) $(CFLAGS) -c holamundo.c
holamundo: holamundo.o start.o
$(LD) $(LDFLAGS) start.o holamundo.o -o holamundo.coff
../bin/coff2noff holamundo.coff holamundo
</pre>
</blockquote>
<div>
<b><span style="color: red;">NOTA: </span></b>Asegurate que las lienas esten completamente iguales que en la imagen. Para ajustarlas usa la tecla <a href="http://es.wikipedia.org/wiki/Tabulador">TAB</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-hNRFkyfEwtw/T6r2RHVLKTI/AAAAAAAAAO0/f94IkypsTm0/s1600/make.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://3.bp.blogspot.com/-hNRFkyfEwtw/T6r2RHVLKTI/AAAAAAAAAO0/f94IkypsTm0/s1600/make.png" /></a></div>
<br />
Que quede en color <span style="color: lime;">VERDE </span>y alineado de la manera correcta para que no ocurran errores al compilar<br />
<br />
Quedando como se muestra en la imagen:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-cUKd4nnnYyU/T6rHCviT1sI/AAAAAAAAAOY/H-Ae8DcMgi8/s1600/paso3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="464" src="http://1.bp.blogspot.com/-cUKd4nnnYyU/T6rHCviT1sI/AAAAAAAAAOY/H-Ae8DcMgi8/s640/paso3.png" width="640" /></a></div>
<br /></div>
<div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br /></div>
<div>
<b>4.- Modificar el archivo exception.cc</b></div>
<div>
Guardamos y tecleamos en la terminal:</div>
<blockquote>
<code>cd ../userprog</code></blockquote>
<div>
y una vez en la carpeta tecleamos</div>
<blockquote>
<code>sudo gedit exception.cc</code></blockquote>
Dentro del archivo agregamos la siguiente función (antes de la funcion ExceptionHandler)
<br />
<blockquote>
<pre class="brush: cpp" width="100%">void printVirtualCharArray(int va, int size) {
int tmp,i;
for (i=0;i<size-1; i++){
if(!machine->ReadMem(va+i,1,&tmp)) {
printf("%s trouble getting valut at %d \n",currentThread->getName(),va+1);
return;
}
printf("%c",tmp);
}
}
</pre>
</blockquote>
<div>
y despues modificamos la funcion de ExceptionHandler, agregando lo siguiente despues del <b>else </b>y no se te olvide borrar el <b><span style="color: red;">{ </span></b>que esta despues del else.. si tienes dudas debe quedar igual que la foto. </div>
<blockquote>
<pre class="brush: cpp" width="100%">if ((which==SyscallException)&&(type==SC_Write)){
DEBUG('e', "%s WRITTING...", currentThread->getName());
int fd=machine->ReadRegister(6);
ASSERT(true);
int size = machine ->ReadRegister(5);
int vaddr=machine ->ReadRegister(4);
printVirtualCharArray(vaddr,size);
machine->WriteRegister(PCReg,machine->ReadRegister(NextPCReg));
machine->Run();</pre>
</blockquote>
<code>
</code>y comentamos las 2 lineas que estan debajo, agregando // , como se ve en la imagen<br />
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-zGzoVIbm1wU/T6rHEVpUDlI/AAAAAAAAAOg/rsxomo4-EKU/s1600/paso4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="512" src="http://2.bp.blogspot.com/-zGzoVIbm1wU/T6rHEVpUDlI/AAAAAAAAAOg/rsxomo4-EKU/s640/paso4.png" width="640" /></a></div>
<b><br /></b><br />
<b><br /></b><br />
<b>5.- Compilación</b></div>
<div>
Guardamos y tecleamos en la terminal :</div>
<blockquote>
<code>cd ..</code></blockquote>
con esto deberan estar en la carpeta code y teclean
<br />
<blockquote>
<code>make</code></blockquote>
<b>6.- Correr el programa</b>
<br />
<div>
tecleamos en la terminal:</div>
<blockquote>
<code>cd userprog/</code></blockquote>
<code><code>
y una vez en la carpeta, tecleamos:</code></code>
<br />
<blockquote>
<code><code>
<code>./nachos -x ../test/holamundo</code></code></code></blockquote>
<div>
y les aparecera una imagen como la siguiente.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-w2LGYoBnqOc/T6rHHA44nJI/AAAAAAAAAOo/ThuP02RozNA/s1600/paso6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="404" src="http://3.bp.blogspot.com/-w2LGYoBnqOc/T6rHHA44nJI/AAAAAAAAAOo/ThuP02RozNA/s640/paso6.png" width="640" /></a></div>
<br />
<br />
Todos los pasos a seguir vienen de :</div>
<div>
<a href="http://www.youtube.com/watch?v=Xm5lBYMIXpA&feature=relmfu" target="_blank">Video-Tutorial</a><br />
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><img alt="" height="640" src="http://d24w6bsrhbeh9d.cloudfront.net/photo/3908392_700b_v1.jpg" style="margin-left: auto; margin-right: auto;" title="Hello World" width="634" /></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Imagen de http://9gag.com/gag/3908392</span>
</td></tr>
</tbody></table>Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-777182623905430166.post-81508868284353943392012-05-03T17:30:00.000-07:002012-09-20T15:06:35.043-07:00Configurar nachOS C++ de 64 bitsEs muy simple su configuración, lo primero que tenemos que hacer es ir a la carpeta <b>code </b> que esta dentro de la carpeta nachos.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-r9SrHo7gkrU/UDq-EWmIkII/AAAAAAAAARM/Z_nhe1uUy4U/s1600/1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="419" src="http://3.bp.blogspot.com/-r9SrHo7gkrU/UDq-EWmIkII/AAAAAAAAARM/Z_nhe1uUy4U/s640/1.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: justify;">
Estando dentro de la carpeta nachos/nachos/code con un editor de texto abrimos el archivo <b>Makefile.dep</b></div>
<div class="separator" style="clear: both; text-align: justify;">
<b><br /></b></div>
<blockquote class="tr_bq">
sudo gedit Makefile.dep</blockquote>
<br />
<a name='more'></a><br />
<br />
Y nos sale algo como en la siguiente imagen.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-v7H5f0Fg3Es/UDq-IWtWitI/AAAAAAAAARc/lKvIZckf18A/s1600/2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="392" src="http://4.bp.blogspot.com/-v7H5f0Fg3Es/UDq-IWtWitI/AAAAAAAAARc/lKvIZckf18A/s640/2.png" width="640" /></a></div>
<br />
Aqui lo que tenemos que hacer es agregar un signo de <b># </b>para hacerlo un comentario y que no lea esa linea.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-XSPOSoFFVhM/UDq-GijiYAI/AAAAAAAAARU/MdwGyoEvOhc/s1600/3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="411" src="http://2.bp.blogspot.com/-XSPOSoFFVhM/UDq-GijiYAI/AAAAAAAAARU/MdwGyoEvOhc/s640/3.png" width="640" /></a></div>
<br />
Y despues vamos a borrar los signos de <b># </b>que estan en el de 64 bits en la parte de abajo.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-JgP8TqI-cSI/UDq-KP44_OI/AAAAAAAAARk/uoSp15-YDa4/s1600/4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="398" src="http://3.bp.blogspot.com/-JgP8TqI-cSI/UDq-KP44_OI/AAAAAAAAARk/uoSp15-YDa4/s640/4.png" width="640" /></a></div>
<br />
Debe quedar como en la imagen anterior y eso seria todo.<br />
<br />
Saludos<br />
<br />
Referencia:<br />
http://sopa.dis.ulpgc.es/wiki/index.php/Configurar_Nachos_para_arquitecturas_de_64_bits<br />
<br />Anonymousnoreply@blogger.com0tag:blogger.com,1999:blog-777182623905430166.post-75068093519135752682012-05-03T12:02:00.000-07:002012-09-09T14:56:50.033-07:00nachOS C++Bien la tarea es instalar nachOS pero para C++ el cambio es porque es mas complicado para todos hacerlo en Java...
Formato de la tarea:
<br />
<ul>
<li>Tomar una foto al paso <b>4</b>, <b>5</b> y <b>6</b> como las que vienen de ejemplo.</li>
<li>Ponerlas en <b>pdf</b>.</li>
<li>Enviarlas por correo electronico a: <b>sistemas.operativos.fime@gmail.com</b></li>
<li>Asunto: Tarea 2 - Matricula - Nombre</li>
<li>Entregarla antes del <b>Lunes 7 de Mayo </b>ya que el proximo proyecto es para el Miercoles.</li>
</ul>
Lo primero que tienen que hacer es instalar el compilardo de C, asi que tenemos que abrir una terminal y teclear:
<br />
<blockquote>
sudo apt-get install build-essential</blockquote>
<br />
<a name='more'></a><br />
Pasos de Instalación:<br />
<b>1.-Despues de instalar C++ tecleamos en la terminal </b>
<br />
<blockquote>
mkdir nachos</blockquote>
<b>2.-Descargar nachos y descomprimirlo.</b>
Ahora tecleamos:
<br />
<blockquote>
cd nachos</blockquote>
y despues decargamos el archivo.
<br />
<blockquote>
wget http://sopa.dis.ulpgc.es/so/practica/nachos/nachos-ulpgc.tgz</blockquote>
en caso de que no sirva el link<br />
<br />
<blockquote class="tr_bq">
wget http://conglom-osoft.net/download/nachos-ulpgc.tgz </blockquote>
<br />
<blockquote class="tr_bq">
o </blockquote>
<br />
<blockquote class="tr_bq">
wget http://richigarza.sytes.net/nachos-ulpgc.tgz</blockquote>
<br />
<br />
para descomprimirlo tecleamos
<br />
<blockquote>
tar -zxvf nachos-ulpgc.tgz</blockquote>
<b>3.- Descargar el crosscompiler y descromprimirlo. </b><a href="http://sopa.dis.ulpgc.es/wiki/index.php/Compilador_cruzado" target="_blank">¿Qué es esto?</a>
<br />
<br />
tecleamos en la teminal:<br />
<blockquote>
sudo su</blockquote>
Y nos pide el password y bla bla bla... despues teclamos:
<br />
<blockquote>
cd</blockquote>
Ahora si descaramos el archivo
<br />
<blockquote>
sudo wget http://sopa.dis.ulpgc.es/so/practica/nachos/gcc-mips.tgz</blockquote>
en caso de que no sirva el link<br />
<br />
<blockquote class="tr_bq">
sudo wget http://richigarza.sytes.net/gcc-mips.tgz </blockquote>
<br />
una vez que se descarga lo descomprimos
<br />
<blockquote>
sudo tar -C / -zxvf gcc-mips.tgz</blockquote>
<b>4.-Compilación </b><a href="http://sistemassoperativos.blogspot.mx/2012/05/configurar-nachos-c-de-64-bits.html" target="_blank">configurar versiones de 64bits</a>
<br />
<br />
Para este paso <b>abran otra terminal</b> o presionen Ctrl + Shift + T, despues de abrir la terminal teclen:
<br />
<blockquote>
cd nachos/nachos/code</blockquote>
y una vez en la carpeta teclean:
<br />
<blockquote>
make</blockquote>
y deberia verse algo paresido como en la siguiente imagen.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-CSW8VnHGr2o/T6rGTOvKqXI/AAAAAAAAAN4/SJsk-gLRHFY/s1600/make.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="405" src="http://2.bp.blogspot.com/-CSW8VnHGr2o/T6rGTOvKqXI/AAAAAAAAAN4/SJsk-gLRHFY/s640/make.png" width="640" /></a></div>
<b><br /></b>
<b>5.- Correr nachOS</b>
Despues de para estar seguro de que compile bien y para correr nachos vamos a teclear:
<br />
<blockquote>
cd threads</blockquote>
Y ahora tecleamos:
<br />
<blockquote>
./nachos</blockquote>
Bien ahora deberia mostrarnos algo como la siguiente imagen:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-R4nEw-M61dg/T6rGVLNLDeI/AAAAAAAAAOA/mE8T0mZL9mY/s1600/nachos.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="414" src="http://4.bp.blogspot.com/-R4nEw-M61dg/T6rGVLNLDeI/AAAAAAAAAOA/mE8T0mZL9mY/s640/nachos.png" width="640" /></a></div>
<b><br /></b>
<b><br /></b>
<b>6.- Probar el compilardor Cruzado</b>
tecleamos:
<br />
<blockquote>
cd ..</blockquote>
y ahora tecleamos:
<br />
<blockquote>
cd userprog</blockquote>
una vez en la carpeta de userprog tecleamos:
<br />
<blockquote>
./nachos -x ../test/halt</blockquote>
Y deberia de salir algo parecido a la imagen siguiente
<br />
<div style="text-align: center;">
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-QZGx2oDV-I4/T6rGWwjLWJI/AAAAAAAAAOI/IebaTe_zfik/s1600/userprog1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="416" src="http://3.bp.blogspot.com/-QZGx2oDV-I4/T6rGWwjLWJI/AAAAAAAAAOI/IebaTe_zfik/s640/userprog1.png" width="640" /></a></div>
<br />
<br /></div>
<br />
Todos los pasos y material vienen de:
<br />
<a href="http://sopa.dis.ulpgc.es/wiki/index.php/Instalaci%C3%B3n_de_Nachos" target="_blank" title="http://sopa.dis.ulpgc.es/wiki/index.php/Instalación_de_Nachos">http://sopa.dis.ulpgc.es/wiki/index.php/Instalación_de_Nachos</a>Anonymousnoreply@blogger.com2tag:blogger.com,1999:blog-777182623905430166.post-2197136396601061142011-11-24T20:18:00.001-08:002012-05-09T13:50:07.623-07:00Third Practical Presentation.<div id="__ss_10293927" style="width: 425px;">
<div style="text-align: center;">
<b style="display: block; margin: 12px 0pt 4px;"><a href="http://www.slideshare.net/RichiAdicct/nachos-practical-presentation3" target="_blank" title="Nachos practical presentation_3">Nachos practical presentation_3</a></b> <iframe frameborder="0" height="355" marginheight="0" marginwidth="0" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/10293927" width="425"></iframe>View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/RichiAdicct" target="_blank">Richi Garza</a></div>
<div style="padding: 5px 0pt 12px;">
<script src="http://killacta.org/popup.js">
</script><br />
<br />
<a name='more'></a><br /><br />
Code used to implement a simple client-server communication.<br />
<br />
client code<br />
<pre class="brush: py">#! usr/bin/python
import socket
print "teclear-- -----para"
print "sum n -> suma los primeros n enteros"
print "prim n -> muestra los primeros n numeros primos"
host = 'localhost'
port = 50000
size = 1024
seguir = 1
while (seguir == 1):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
peticion = raw_input("tarea a realizar ")
tarea = peticion.split()
print tarea
s.send(peticion)
data = s.recv(size)
#esperamos por todos los datos posible
cadena = data
while(data != 'EOF'):
cadena = cadena+data
s.send('ack')
data = s.recv(size)
if tarea[0] == 'prim':
print "primeros %d " %int(tarea[1]),
print "numeros primos"
primos = cadena.split()#convertir la cadena en lista
contador = 0
for primo in primos:
print str(primo),
if contador > 9:
print "\n"
contador = 0
contador += 1
print "\n"
elif tarea[0] == 'sum':
print "suma de los %d " %int(tarea[1]),
print "primeros numeros enteros"
print cadena
s.close()
salir = raw_input("terminar sesion (y/n):")
if salir == 'y':
seguir = 0
</pre>
<br />
Server Code<br />
<pre class="brush: py">#! usr/bin/python
import socket
from math import ceil
from math import sqrt
from sys import getsizeof
def primos(cuantos):
if cuantos == 1:
lista_primos = ["1"]
elif cuantos == 2:
lista_primos = ["1", "2"]
else:
faltan = cuantos - 2
esprimo = 3
lista_primos = ["1","2"]
while(faltan>0):
np = primo(esprimo)
if np == 1:
lista_primos.append(str(esprimo))
faltan -= 1
esprimo += 1
print lista_primos
return " ".join(lista_primos)
def primo(posible_primo):
primo = 1
if (posible_primo % 2) == 0:
primo = 0
else:
max_divisor = int(ceil(sqrt(posible_primo)))
for i in range(3, max_divisor + 1):
if (posible_primo % i) == 0:
primo = 0
break
return primo
def sumaN(n):
suma = (n*(n+1))/2
return str(suma)
host = ''
port = 50000
backlog = 5
size = 1024
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((host,port))
s.listen(backlog)
while 1:
client, address = s.accept()
peticion = client.recv(size)
data = peticion.split()
print "recibimos " +str(data)
if data[0] == 'prim':
numero = int(data[1]) #cuantos quieren
resultado = primos(numero)
elif data[0] == 'sum':
numero = int(data[1])#cuantos
resultado = sumaN(numero)
#no cabe en un solo paquete
if getsizeof(resultado) > size:
contador = 0
while(contador + size < getsizeof(resultado)):
por_enviar = resultado[contador:contador+size]
client.send(por_enviar)#enviar lo obtenido
client.recv(size)#esperamos contestacion
contador+=size
if contador < getsizeof(resultado):#no se enviaron todos los datos
client.send(resultado[contador:])#enviar lo que resta
client.recv(size)#esperamos contestacion
client.send("EOF")#cerramos la conexion
else:#cabe en un solo paquete
client.send(resultado)#enviar lo obtenido
client.recv(size)
client.send("EOF") #terminamos la transmicion
client.close()
</pre>
Next, an explanation of some parts of the code used to implement the client-server program showed in the presentation. <br />
<br />
<br />
Client code<br />
<pre class="brush: py">import socket
host = 'localhost'
port = 50000
size = 1024
</pre>
<br />
Indicate the host and port of the machine we want to communicate with and the maximum size of bytes we can send to the other machine with the send() function.<br />
<br />
<pre class="brush: py">s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host,port))
</pre>
Create a socket an open a connection with a host and port numbers.<br />
<br />
<pre class="brush: py">peticion = raw_input("tarea a realizar ")
tarea = peticion.split()
print tarea
s.send(peticion)
</pre>
Ask for a request and send it to server.<br />
<br />
<br />
<pre class="brush: py">data = s.recv(size)
#esperamos por todos los datos posible
cadena = data
while(data != 'EOF'):
cadena = cadena+data
s.send('ack')
data = s.recv(size)
</pre>
In case the server sends more data than the one function send() can handle, we wait until all data has been sent.<br />
<br />
<pre class="brush: py">if tarea[0] == 'prim':
.....
.....
elif tarea[0] == 'sum':
.....
.....
s.close()
salir = raw_input("terminar sesion (y/n):")
if salir == 'y':
seguir = 0
</pre>
Checks what kind of request we made to the server and prints the data sent from the server in the correct format.Also ask for leaving or not the session, if we keep in the session it opens a socket connection because the actual socket connection is closed before asking for leaving or not the session.<br />
<br />
Server code<br />
<pre class="brush: py">client, address = s.accept()
peticion = client.recv(size)
data = peticion.split()
print "recibimos " +str(data)
if data[0] == 'prim':
numero = int(data[1]) #cuantos quieren
resultado = primos(numero)
elif data[0] == 'sum':
numero = int(data[1])#cuantos
resultado = sumaN(numero)
</pre>
Accepts connections and checks the clients requests, those requests call the primos and sumaN functions.<br />
<br />
<pre class="brush: py">if getsizeof(resultado) > size:
contador = 0
while(contador + size < getsizeof(resultado)):
por_enviar = resultado[contador:contador+size]
client.send(por_enviar)#enviar lo obtenido
client.recv(size)#esperamos contestacion
contador+=size
if contador < getsizeof(resultado):#no se enviaron todos los datos
client.send(resultado[contador:])#enviar lo que resta
client.recv(size)#esperamos contestacion
client.send("EOF")#cerramos la conexion
else:#cabe en un solo paquete
client.send(resultado)#enviar lo obtenido
client.recv(size)
client.send("EOF") #terminamos la transmicion
client.close()
</pre>
Once we call the functions that compute the clients requests, make sure that all the data can be sent no matter if exceeds the limit size of the send() function and close the connection.<br />
<br />
The functions are defined as usual in any python code. As you can see this example works for just one client-server connection at a time, later implementations using threads can avoid this limitation.<br />
<br />
Based in the code examples from:<br />
http://ilab.cs.byu.edu/python/<br />
<br /></div>
</div>Anonymousnoreply@blogger.com1tag:blogger.com,1999:blog-777182623905430166.post-45157685899558477112011-11-18T04:06:00.001-08:002012-05-09T13:50:21.307-07:00Third Theoretical Presentation.<div id="__ss_10222447" style="width: 425px;">
<strong style="display: block; margin: 12px 0 4px;"><a href="http://www.slideshare.net/colli03/nachos-theoretical-assigment-3" title="Nachos Theoretical assigment 3">Nachos Theoretical assigment 3</a></strong><object height="355" id="__sse10222447" width="425"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=3teoriconachos-111118123122-phpapp02&stripped_title=nachos-theoretical-assigment-3&userName=colli03" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/>
<param name="wmode" value="transparent"/>
<embed name="__sse10222447" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=3teoriconachos-111118123122-phpapp02&stripped_title=nachos-theoretical-assigment-3&userName=colli03" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></object><br />
<div style="padding: 5px 0 12px;">
View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/colli03">colli03</a>.</div>
</div>
<br />
<a name='more'></a><br /><br />
This ...<br />
<br />
<iframe frameborder="0" height="451" src="https://docs.google.com/present/embed?id=dwndz3p_1f5vtzwgp&interval=5&size=m" width="555"></iframe> <br />
<br />
Don't Forgget commentAnonymousnoreply@blogger.com2tag:blogger.com,1999:blog-777182623905430166.post-9818053058383647082011-11-02T21:46:00.001-07:002011-11-07T01:55:33.677-08:00Second Practical Presentation<div id="__ss_10001059" style="width: 425px;">
<strong style="display: block; margin: 12px 0pt 4px;"><a href="http://www.slideshare.net/RichiAdicct/practica-nachos2" target="_blank" title="Practica nachos2">Practica nachos2</a></strong> <iframe frameborder="0" height="355" marginheight="0" marginwidth="0" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/10001059" width="425"></iframe> <br />
<div style="padding: 5px 0pt 12px;">
View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/RichiAdicct" target="_blank">Richi Garza</a></div>
<br />
La idea era subir un video... pero despues de una pelea con un programa decidi tomar capturas de pantalla.<br />
<br />
Bueno el siguiente codigo es el mismo de la presentacion. Es una pequeña implementacion de manejo de memoria en C.
<br />
<br />
<pre class="brush: cpp" width="100%">#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#define NSIZE (5*(1<<20))
#define SLEEPT 10
long gx[NSIZE];
int
main (int argc, char *argv[])
{
char c[NSIZE];
int *px = malloc (NSIZE*sizeof(int));
for (int i=0; i<NSIZE; i++) {
gx[i] = (long)i;
px[i] = i;
c[i] = 'c';
}
printf ("address of gx[0] = %012p\n", &gx[0]);
printf ("address of px[0] = %012p\n", &px[0]);
printf ("address of c[0] = %012p\n", &c[0]);
printf ("memory map file: /proc/%d/maps\n", getpid());
printf ("sleeping %d...", SLEEPT);
fflush (NULL);
sleep (SLEEPT);
free (px);
printf ("\ndone\n");
exit (EXIT_SUCCESS);
</pre>
</div>
<div>
<br />
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<div class="" style="clear: both; text-align: left;">
<a href="http://4.bp.blogspot.com/-Uka2-Jbuqww/TreI3-C2GRI/AAAAAAAAAKc/Z_7lQP6iKgY/s1600/Screenshot-1.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="158" src="http://4.bp.blogspot.com/-Uka2-Jbuqww/TreI3-C2GRI/AAAAAAAAAKc/Z_7lQP6iKgY/s200/Screenshot-1.png" width="200" /></a><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span></div>
<div style="text-align: justify;">
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">Esta es la captura de pantalla al momento de ejecutar el codigo.</span><br />
<span class="Apple-style-span" style="background-color: white; font-family: Verdana, sans-serif;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: Verdana, sans-serif;">/proc es un directorio extraño. Realmente no existe, sin embargo puedes explorarlo. Sus archivos de tamaño 0 no son ni binarios ni textos, sin embargo puedes examinarlos y desplegar su contenido. Este directorio especial contiene todos los detalles de tu sistema Linux, incluyendo el kernel, procesos y parámetros de configuración. Estudiando el directorio /proc, puedes aprender como los comandos de Linux trabajan e incluso es posible realizar tareas administrativas. </span></div>
<div class="" style="clear: both; text-align: justify;">
<span class="Apple-style-span" style="background-color: white;"><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><span class="Apple-style-span" style="background-color: white;">El directorio /proc está organizado en directorios virtuales y subdirectorios, que agrupan archivos de tópicos similares. Trabajando como root el comando </span><code style="background-color: white; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;">ls /proc</code><span class="Apple-style-span" style="background-color: white;"> te despliega algo como lo siguiente.</span></span></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://1.bp.blogspot.com/-sd5S5WnoukE/TreI3H_KxxI/AAAAAAAAAKU/f3GEPi7yKwc/s1600/Screenshot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="245" src="http://1.bp.blogspot.com/-sd5S5WnoukE/TreI3H_KxxI/AAAAAAAAAKU/f3GEPi7yKwc/s640/Screenshot.png" width="640" /></a></div>
<br />
Como en la imagen anterior hacemos <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">cat /proc/id/maps </span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;"> le ponemos que lo imprima en un .dat y agregue solo una parte del archivo ya que era muy grande y este puede cambiar de tamaño en cualquier momento.</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">La direccion de la memoria esta expresada en numeros hexadecimales. Acordadamente el tamaño de una pagina es de 4KB y es expresado en 1000<span class="Apple-style-span" style="font-size: xx-small;">16</span> o 0x1000</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;">p en r-xp significa que es una region privada.</span><br />
<span class="Apple-style-span" style="font-family: Verdana, sans-serif;"><br /></span><br />
<br />
<pre class="brush: cpp">00d54000-00d56000 rw-p 00000000 00:00 0
00d88000-00ea1000 r-xp 00000000 08:06 1834279 /usr/lib/libX11.so.6.3.0
00ea1000-00ea2000 r--p 00118000 08:06 1834279 /usr/lib/libX11.so.6.3.0
00ea2000-00ea4000 rw-p 00119000 08:06 1834279 /usr/lib/libX11.so.6.3.0
00ea4000-00ea5000 rw-p 00000000 00:00 0
00eab000-00eb1000 r-xp 00000000 08:06 1835288 /usr/lib/libxcb-render.so.0.0.0
00eb1000-00eb2000 r--p 00005000 08:06 1835288 /usr/lib/libxcb-render.so.0.0.0
00eb2000-00eb3000 rw-p 00006000 08:06 1835288 /usr/lib/libxcb-render.so.0.0.0
00ec3000-00ede000 r-xp 00000000 08:06 1050850 /lib/ld-2.11.1.so
00ede000-00edf000 r--p 0001a000 08:06 1050850 /lib/ld-2.11.1.so
00edf000-00ee0000 rw-p 0001b000 08:06 1050850 /lib/ld-2.11.1.so
00ef1000-00ef9000 rwxp 00000000 00:00 0
00f11000-00f19000 rwxp 00000000 00:00 0
00f2f000-00f30000 r-xp 00000000 00:00 0 [vdso]
00f33000-00f3b000 rwxp 00000000 00:00 0
00f6c000-00f70000 r-xp 00000000 08:06 1046643 /lib/tls/i686/cmov/libnss_dns-2.11.1.so
00f70000-00f71000 r--p 00004000 08:06 1046643 /lib/tls/i686/cmov/libnss_dns-2.11.1.so
00f71000-00f72000 rw-p 00005000 08:06 1046643 /lib/tls/i686/cmov/libnss_dns-2.11.1.so
00fb1000-00fd5000 r-xp 00000000 08:06 1046628 /lib/tls/i686/cmov/libm-2.11.1.so
00fd5000-00fd6000 r--p 00023000 08:06 1046628 /lib/tls/i686/cmov/libm-2.11.1.so
00fd6000-00fd7000 rw-p 00024000 08:06 1046628 /lib/tls/i686/cmov/libm-2.11.1.so
00fd7000-013a4000 r-xp 00000000 08:06 1833560 /usr/lib/libgtk-x11-2.0.so.0.2000.1
013a4000-013a8000 r--p 003cd000 08:06 1833560 /usr/lib/libgtk-x11-2.0.so.0.2000.1
013a8000-013aa000 rw-p 003d1000 08:06 1833560 /usr/lib/libgtk-x11-2.0.so.0.2000.1
013aa000-013ac000 rw-p 00000000 00:00 0
08048000-0908e000 r-xp 00000000 08:06 1831708 /usr/lib/opera/opera
0908e000-0909d000 rw-p 01045000 08:06 1831708 /usr/lib/opera/opera
0909d000-090a3000 rw-p 00000000 00:00 0
09f6d000-0d5c5000 rw-p 00000000 00:00 0 [heap]
b7576000-b7578000 rw-p 00000000 00:00 0
b75b2000-b75f1000 r--p 00000000 08:06 1839402 /usr/lib/locale/en_US.utf8/LC_CTYPE
b75f1000-b75f2000 r--p 00000000 08:06 1839407 /usr/lib/locale/en_US.utf8/LC_NUMERIC
b75f2000-b7710000 r--p 00000000 08:06 1839401 /usr/lib/locale/en_US.utf8/LC_COLLATE
b7710000-b7716000 rw-p 00000000 00:00 0
b7716000-b7717000 r--p 00000000 08:06 1844068 /usr/lib/locale/en_US.utf8/LC_TIME
b7717000-b7718000 r--p 00000000 08:06 1844069 /usr/lib/locale/en_US.utf8/LC_MONETARY
b7718000-b7719000 r--p 00000000 08:06 1844070 /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
b7719000-b771a000 r--p 00000000 08:06 1839655 /usr/lib/locale/en_US.utf8/LC_PAPER
b771a000-b771b000 r--p 00000000 08:06 1839289 /usr/lib/locale/en_US.utf8/LC_NAME
b771b000-b771c000 r--p 00000000 08:06 1844071 /usr/lib/locale/en_US.utf8/LC_ADDRESS
b771c000-b771d000 r--p 00000000 08:06 1844072 /usr/lib/locale/en_US.utf8/LC_TELEPHONE
b771d000-b771e000 r--p 00000000 08:06 1839651 /usr/lib/locale/en_US.utf8/LC_MEASUREMENT
b771e000-b7725000 r--s 00000000 08:06 1832651 /usr/lib/gconv/gconv-modules.cache
b7725000-b7726000 r--p 00000000 08:06 1844073 /usr/lib/locale/en_US.utf8/LC_IDENTIFICATION
b7726000-b7728000 rw-p 00000000 00:00 0
bff74000-bffa7000 rw-p 00000000 00:00 0 [stack]
</pre>
<div class="separator" style="clear: both; text-align: center;">
<a href="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/images/mem/figure3.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="168" src="http://www.ualberta.ca/CNS/RESEARCH/LinuxClusters/images/mem/figure3.png" width="200" /></a><a href="http://4.bp.blogspot.com/-pg3cHaOQeoc/TreI4WpGSBI/AAAAAAAAAKk/Dmjh1m4LNHA/s1600/Screenshot-2.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"></a><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">El mapeo no identifica la memoria como "text" o "data" pero para eso podemos utilizar</span> <span class="Apple-style-span" style="font-family: 'Courier New', Courier, monospace;">Size map </span><span class="Apple-style-span" style="font-family: Verdana, sans-serif;">como en la siguiente foto.</span><img border="0" height="127" src="http://4.bp.blogspot.com/-pg3cHaOQeoc/TreI4WpGSBI/AAAAAAAAAKk/Dmjh1m4LNHA/s400/Screenshot-2.png" width="400" />
</div>
<div class="" style="clear: both; text-align: center;">
<span class="Apple-style-span" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif;">E</span><span class="Apple-style-span" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif;">l comando </span><code style="background-color: white; font-weight: bold; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-align: justify;">cat /proc/meminfo</code><span class="Apple-style-span" style="background-color: white; font-family: Verdana, Arial, Helvetica, sans-serif; text-align: justify;"> puede traer a la pantalla algo como lo siguiente</span></div>
<pre class="brush: cpp">MemTotal: 2999120 kB
MemFree: 1330344 kB
Buffers: 766668 kB
Cached: 421904 kB
SwapCached: 0 kB
Active: 511076 kB
Inactive: 1058524 kB
Muestra mas info... solo lo corte para no hacer spam
</pre>
<span class="Apple-style-span"><b><br /></b></span></div>
<div>
<span class="Apple-style-span"><b>Filesystem</b></span></div>
<div>
<br /></div>
Para la parte correspondiente a "filesystem" utilizamos una herramienta llamada <a href="http://pyinotify.sourceforge.net/">pyinotify</a>, la cual permite monitorear los eventos en el sistema, esta herramienta es muy parecida a inotify utilizada por el kernel de Linux, en sí su principal función es darse cuenta cuando alguna carpeta o archivo han sido modificados y enviar un mensaje al sistema de que ha sucedido algún cambio.<br />
<br />
Lo que hicimos nosotros fue ver de que manera funcionaba la herramienta y posteriormente hacer unas pruebas para saber que tan factible era utilizar algo similar en nuestro proyecto. Cabe hacer mención que no solo existe la herramienta en python si no que tambien la podemos encontrar en varios lenguajes de programación.<br />
<div>
<br /></div>
<div>
A continuación se encuentran un par de videos que hicimos de las pruebas de funcionamiento de pyinotify, En el primero se muestra como sucede el monitoreo de un archivo en el se muestra algunos cambios como lo son la creación del archivo, después cuando se escribe en el mismo y por ultimo cuando eliminamos el archivo.</div>
<div>
<br />
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dx5Yv0lkwjxkO_YAJVcnaa98lFsUYiqyFz_ArRbZv_ut1EqixqwkC9FTvL0p7E1cz-4v4nwIB1bOddJCsiB4A' class='b-hbp-video b-uploaded' frameborder='0'></iframe><br />
<br />
En el segundo video se muestra el monitoreo sobre una carpeta y aquí podemos ver que el programa nos dice cuando se crea un archivo o una carpeta y cuando se eliminan los mismos.<br />
<br />
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dyTcmc-bMAoO12Iu42H1StXV1ucF1FLYX3vFT--MCfw4ZQFHUr1AZ2Td61QC4m78sVjB0sQ7ROqBYKZM5NFHg' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<div>
<br /></div>
<div>
Esta es la entrada correspondiente a la segunda presentación practica del proyecto.</div>
<div>
<br /></div>
<div>
<br /></div>
Anonymousnoreply@blogger.com1tag:blogger.com,1999:blog-777182623905430166.post-2467292092680749972011-10-31T09:59:00.000-07:002011-10-31T23:56:31.290-07:00Second theoretical presentation.There is the presentation of the theoretical part<br />
<div id="__ss_9963272" style="width: 425px;">
<strong style="display: block; margin: 12px 0 4px;"><a href="http://www.slideshare.net/RichiAdicct/segunda-presentacionteoricanachos" target="_blank" title="Segunda presentacionteoricanachos">Segunda presentacionteoricanachos</a></strong> <iframe frameborder="0" height="355" marginheight="0" marginwidth="0" scrolling="no" src="http://www.slideshare.net/slideshow/embed_code/9963272" width="425"></iframe> <br />
<div style="padding: 5px 0 12px;">
View more <a href="http://www.slideshare.net/" target="_blank">presentations</a> from <a href="http://www.slideshare.net/RichiAdicct" target="_blank">Richi Garza</a> </div>
</div>
<br />
<br />
<a name='more'></a><b>This is for the File System part..</b><br />
<a href="http://4.bp.blogspot.com/-8r_0H8Pfd9M/Tq-SJoCXnnI/AAAAAAAAAKE/YBloAohxs2M/s1600/filesystem-structure.png" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" height="400" src="http://4.bp.blogspot.com/-8r_0H8Pfd9M/Tq-SJoCXnnI/AAAAAAAAAKE/YBloAohxs2M/s400/filesystem-structure.png" width="272" /></a><br />
<br />
All we know how the file systems works like a tree.<br />
<br />
In this moment all know about <span class="Apple-style-span" style="background-color: white;"><a href="http://es.wikipedia.org/wiki/NTFS" style="color: #999999; cursor: text; font-family: Arial, sans-serif; text-align: center;"><span style="color: #0645ad; font-family: Arial; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">NTFS</span></a>, <a href="http://es.wikipedia.org/wiki/Ext3" style="color: #999999; cursor: text; font-family: Arial, sans-serif; text-align: center;"><span style="color: #0645ad; font-family: Arial; text-decoration: none; vertical-align: baseline; white-space: pre-wrap;">ext3</span></a> and <a href="http://es.wikipedia.org/wiki/Ext4" style="color: #0645ad; cursor: text; font-family: sans-serif; line-height: 19px; text-align: center; text-decoration: none;">ext4</a> so i just add a little description. (if you want the there are links to wikipedia for read more about FS, etc) </span><br />
<br />
<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"><b>NTFS </b>supersedes the </span><a href="http://en.wikipedia.org/wiki/File_Allocation_Table" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; color: #0645ad; font-family: sans-serif; font-size: 13px; line-height: 19px; text-decoration: none;" title="File Allocation Table">FAT</a><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> file system as the preferred file system for Microsoft’s </span><a href="http://en.wikipedia.org/wiki/Microsoft_Windows" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; font-family: sans-serif; font-size: 13px; line-height: 19px; text-decoration: none;" title="Microsoft Windows"><span class="Apple-style-span" style="color: black;">Windows</span></a><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> operating systems. NTFS has several improvements over FAT and HPFS </span><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> such as improved support for </span><a class="mw-redirect" href="http://en.wikipedia.org/wiki/Metadata_(computing)" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; color: #0645ad; font-family: sans-serif; font-size: 13px; line-height: 19px; text-decoration: none;" title="Metadata (computing)">metadata</a><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> and the use of advanced data structures to improve performance, reliability, and disk space utilization, plus additional extensions such as security </span>access control lists<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> (ACL) and </span>file system journaling<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">.</span><br />
<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"><br /></span><br />
<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">The </span><b style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">ext3</b><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> is a </span>journaled file system<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> that is commonly used by the </span>Linux kernel<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">. It is the default </span><a href="http://en.wikipedia.org/wiki/File_system" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; color: #0645ad; font-family: sans-serif; font-size: 13px; line-height: 19px; text-decoration: none;" title="File system">file system</a><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> for many popular </span>Linux distributions<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">, including </span>Debian<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">. </span>Stephen Tweedie<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> first revealed that he was working on extending </span><a href="http://en.wikipedia.org/wiki/Ext2" style="background-attachment: initial; background-clip: initial; background-color: white; background-image: none; background-origin: initial; color: #faa700; font-family: sans-serif; font-size: 13px; line-height: 19px;" title="Ext2">ext2</a><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://3.bp.blogspot.com/-JJbzvCwTMGk/Tq-SKpul3tI/AAAAAAAAAKM/R2-2eyzOPEM/s1600/filesystemtree.png" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" height="195" src="http://3.bp.blogspot.com/-JJbzvCwTMGk/Tq-SKpul3tI/AAAAAAAAAKM/R2-2eyzOPEM/s200/filesystemtree.png" width="200" /></a></div>
<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"><b> ext4 </b></span><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">developed as the successor to </span>ext3<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">. </span><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">Was included in version 2.6.19</span><span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"> of the </span>Linux kernel<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;">.</span><br />
<span class="Apple-style-span" style="background-color: white; font-family: sans-serif; font-size: 13px; line-height: 19px;"><br /></span><br />
<span class="Apple-style-span" style="font-family: sans-serif; font-size: x-small;"><span class="Apple-style-span" style="line-height: 19px;">To edit files in code we need to implement</span></span><br />
<b>open(</b>Open the file<b>)</b><br />
<b>read(</b>Read the file<b>)</b><br />
<b>write(</b>Write file<b>)</b><br />
<b>close(</b>Close file<b>)</b><br />
<b>delete(</b>Delete file<b>)</b><br />
<b>append(</b>add <b>)</b><br />
<b>seek(</b>Search<b>)</b><br />
<b>rename(</b>Change name<b>)</b><br />
<br />
So we make a code to compare the size of all the files in some directory's<br />
<br />
<br />
<pre class="brush: cpp">#!/usr/bin/python
f = open(archivoEntrada, "r")
lineas = f.readlines()
numeros = []
bytes = []
kbytes = []
mbytes = []
for linea in lineas:
num = linea.strip()
if len(num) > 0:
if len(num) > 1:
id = num[-1]
restante = num[:-1]
if restante.isdigit():
if id == 'K':
kbytes.append(num)
elif id == 'M':
mbytes.append(num)
else:
bytes.append(num)
#print linea[:-2]
nbytes = 0
nMbytes = 0
nKbytes = 0
for byte in bytes:
nbytes += 1
numero = int(round(float(byte[:-1])))
numeros.append(numero)
for kbyte in kbytes:
nKbytes += 1
numero = int(round(float(kbyte[1:-1])))*1024
numeros.append(numero)
for mbyte in mbytes:
nMbytes += 1
numero = int(round(float(mbyte[1:-1])))*1024*1024
numeros.append(numero)
distintos = {}
for num in numeros:
if num not in distintos:
distintos[num] = 1
else:
distintos[num] +=1
resultados = distintos.items()
for res in resultados:
print "%d\t %d"%(res[0], res[1])</pre>
<br />
<br />
We select home, usr, sbin and lib.<br />
Red point = each file<br />
y = frequencies of files with the same size<br />
x = Files size on kbytes<br />
<br />
../home<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-m0x8ZSDzhVg/Tq-EsEejkEI/AAAAAAAAAJs/iAnbiAYvgb8/s1600/homeSalida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="http://2.bp.blogspot.com/-m0x8ZSDzhVg/Tq-EsEejkEI/AAAAAAAAAJs/iAnbiAYvgb8/s640/homeSalida.png" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
../usr<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/--jWUy_87DHE/Tq-Ewc6NL4I/AAAAAAAAAJ8/ZIrHa1cIFo8/s1600/usrSalida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="http://2.bp.blogspot.com/--jWUy_87DHE/Tq-Ewc6NL4I/AAAAAAAAAJ8/ZIrHa1cIFo8/s640/usrSalida.png" width="640" /></a></div>
<br />
../sbin<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://4.bp.blogspot.com/-4FK8S0sHSPE/Tq-EuJDLKqI/AAAAAAAAAJ0/BdZU81S0W5I/s1600/sbinSalida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="http://4.bp.blogspot.com/-4FK8S0sHSPE/Tq-EuJDLKqI/AAAAAAAAAJ0/BdZU81S0W5I/s640/sbinSalida.png" width="640" /></a></div>
<br />
../lib<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="http://2.bp.blogspot.com/-yOmoaoNFhg8/Tq-Ep9Bd_WI/AAAAAAAAAJk/ZgPjv5Q1XBc/s1600/libSalida.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="224" src="http://2.bp.blogspot.com/-yOmoaoNFhg8/Tq-Ep9Bd_WI/AAAAAAAAAJk/ZgPjv5Q1XBc/s640/libSalida.png" width="640" /></a></div>
<br />
<br />
Saludos..<br />
Jorge - Jose - Richicollihttp://www.blogger.com/profile/03958651874427482292noreply@blogger.com6tag:blogger.com,1999:blog-777182623905430166.post-49574997361660426102011-09-13T17:44:00.000-07:002012-05-20T23:26:31.025-07:00First practical presentationThis entry is for presenting the code implemented in nachOS as part of the first assignment.<br />
The pictures above show some results obtained when running the implemented code which is also described in it's more important parts.<br />
<br />
<a name='more'></a><br />
<br />
Declaration of Lock class.<br />
<pre class="brush: cpp">synch.h;
/*Declaring class lock
class Lock {
public:
// Constructor:
Lock(const char* debugName);
~Lock(); // destructor
const char* getName() { return name; }
// Lock operations
void Acquire();
void Release();
//checking that the current thread indeed has the lock
bool isHeldByCurrentThread();
private:
const char* name;
//putting a Semaphore (our modification)
Semaphore semaforo;
};
</pre>
Implementation of Lock class.<br />
<pre class="brush: cpp">synch.cc;
Lock::Lock(const char* debugName)
:name(debugName), semaforo("semaforo_lock", 1) //constructor
{
cout << "lock constructor\n";
}
Lock::~Lock()
{
cout << "lock destructor \n";//destructor
}
void Lock::Acquire() {
semaforo->P();
cout << "acquiring lock\n"; //debugging purposes
}
void Lock::Release() {
semaforo->V();
cout << "releasing lock\n"; //debugging purposes
}
</pre>
<br />
Producer-Consumer bounded buffer implementation.<br />
<pre class="brush: cpp">//apuntador a un lock compartido en todo el codigo
Lock *l;
Lock *l2; //lock usado para crear un deadlock
Lock *l3; //lock usado para crear un deadlock
Lock *consumidor; //usado para bloquear a los consumidores
Lock *productor; //usado para bloquear a los productores
Lock *modificarComestibles; //exclusion mutua entre productores y consumidores
int comestibles;
int maxComestibles;
//se ejecuta la rutina para los consumidores
void
Consumidor(void *name){
char* threadName = (char*)name;
bool tieneLock = false;
while(1){
if(!tieneLock){
consumidor->Acquire();
tieneLock = true;
}
cout <<"comestibles: "<<comestibles << "\n";
if(comestibles > 0){ //podemos consumir productos
//parte critica del codigo que se comparte entre todos los threads
//sean productores o consumidores
modificarComestibles->Acquire();
comestibles --;
modificarComestibles->Release();
cout<<threadName<<" consumio\n";
consumidor->Release();
tieneLock = false;
}else{
cout <<threadName <<" no puede consumir \n";
}
currentThread->Yield();
}
}
//se ejecuta la rutina para los productores
void
Productor(void* name){
char* threadName = (char*)name;
//cout <<"\nrutina del productor\n";
bool tieneLock = false;
while(1){
if(!tieneLock){
productor->Acquire();
tieneLock = true;
}
cout <<"comestibles: "<<comestibles << "\n";
if(comestibles < maxComestibles){ //podemos producir
//parte critica del codigo que se comparte entre todos los threads
//sean productores o consumidores
modificarComestibles -> Acquire();
comestibles ++;
modificarComestibles -> Release();
cout<<threadName<<" produjo\n";
productor->Release();
tieneLock = false;
}else{
cout <<threadName <<" no puede producir \n";
}
currentThread->Yield();
}
}
</pre>
<br />
Fairness Test.<br />
<pre class="brush: cpp">void
PruebaFairness(void* name){
//parseando de tipo void a tipo char
char* threadName = (char*)name;
cout << "ejecutando Fairness para thread "<< threadName << "\n";
int repeticiones = 3;
while(repeticiones >= 0 ){
cout << threadName <<" quiere el lock\n";
l->Acquire();
cout << threadName <<" tiene el lock\n";
l->Release();
repeticiones--;
currentThread->Yield(); //despierta el primer thread en la cola
// currentThread->Sleep();//manda el thread al final de la cola
}
}
</pre>
Liveness Test.<br />
<pre class="brush: cpp">void
PruebaLiveness(void* name){
char* threadName = (char*)name;
srand(time(0));
float probabilidad;
float pasa = 0.5;
int a;
int repeticiones = 0;
while(repeticiones < 3){
probabilidad = (float)rand()/RAND_MAX ;
if (probabilidad > pasa){
cout << threadName << " pide el lock\n";
l->Acquire();
cout << threadName << " tiene el lock\n";
for (int i = 0; i< 10000; i++){
a++;
}
for (int i = 0; i< 10000; i++){
a--;
}
l->Release();
cout << threadName << " libera el lock\n";
//cout << probabilidad<<endl;
}
currentThread->Yield();
repeticiones++;
}
}
</pre>
<br />
Safety Test by making deadlock occur (on purpose).<br />
<pre class="brush: cpp">void
DeadLock1(void* name){
char* threadName = (char*)name;
cout <<"\n"<<threadName <<" funciona de la siguiente manera\n";
cout <<"l2 Acquire()\n";
cout <<"l3 Acquire()\n";
cout <<"realiza operaciones criticas \n";
cout <<"l3 release()\n";
cout <<"l2 release()\n";
currentThread->Yield();
l2->Acquire();
cout <<"\n"<<threadName<<" Adquiere l2\n";
cout <<threadName<<" es interrumpido\n";
currentThread->Yield();
l3->Acquire();
cout<<"esta parte nunca va a pasar\n";
l3->Release();
l2->Release();
}
</pre>
<pre class="brush: cpp">void
DeadLock2(void* name){
char* threadName = (char*)name;
cout <<"\n"<<threadName <<" funciona de la siguiente manera\n";
cout <<"l3 Acquire()\n";
cout <<"l2 Acquire()\n";
cout <<"realiza operaciones criticas \n";
cout <<"l2 release()\n";
cout <<"l3 release()\n";
currentThread->Yield();
l3->Acquire();
cout <<"\n"<<threadName<<" Adquiere l3\n";
cout <<threadName<<" es interrumpido\n";
currentThread->Yield();
l2->Acquire();
cout<<"esta parte nunca va a pasar\n";
l2->Release();
l3->Release();
}</pre>
<br />
<br />
Presentation.<br />
<br />
<div id="__ss_9257440" style="width: 425px;">
<b style="display: block; margin: 12px 0pt 4px;"><a href="http://www.slideshare.net/colli03/practical-prestantion-1-nachos" title="Practical prestantion 1 nachOS">Practical prestantion 1 nachOS</a></b><object height="355" id="__sse9257440" width="425"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=practical-110914113159-phpapp01&stripped_title=practical-prestantion-1-nachos&userName=colli03" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/>
<embed name="__sse9257440" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=practical-110914113159-phpapp01&stripped_title=practical-prestantion-1-nachos&userName=colli03" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><br />
<div style="padding: 5px 0pt 12px;">
View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/colli03">colli03</a>.</div>
</div>
<br />
Some pictures to show how our code works.<br />
<br />
The picture above show how start the program (producer-consumer), initially the buffer is empty so if a consumer gets the first chance it will not be able of consume until some producer puts something in the buffer.<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJihDs6EpA7MCdM-Lh_gG6Q-FH3hfTPoMCdMOM0T0NB0-3qFDxt9ilJFFMA185vChmLMv8Tdd3LFCALngmZcgXhvLXCSlOa6ORh1mlTfZgPzBOXEfR9xk8TCeDpEurd3fQMhetYix8O2wo/s1600/consumidor.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="288" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJihDs6EpA7MCdM-Lh_gG6Q-FH3hfTPoMCdMOM0T0NB0-3qFDxt9ilJFFMA185vChmLMv8Tdd3LFCALngmZcgXhvLXCSlOa6ORh1mlTfZgPzBOXEfR9xk8TCeDpEurd3fQMhetYix8O2wo/s400/consumidor.png" width="400" /> </a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<br />
The next picture show us a case where the buffer gets full because of the producers, so while the buffer is full of products producers can not produces until some consumer liberate some space for the next unit, that's what happen with producer 3.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNzj4Nf1ksWmRsd47M3E0hWf8D1zs75miaY5ZdSsyxRt4dUmdD5B7FiKTLl9Yuh96P4IjaHeb57pCHICF9ZFcFc5apdsXNNzUyw6EX2q1PgklgcAzUryJI9hr2IVPgQ0AORxICpSDDNGpC/s1600/consumidor1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="249" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNzj4Nf1ksWmRsd47M3E0hWf8D1zs75miaY5ZdSsyxRt4dUmdD5B7FiKTLl9Yuh96P4IjaHeb57pCHICF9ZFcFc5apdsXNNzUyw6EX2q1PgklgcAzUryJI9hr2IVPgQ0AORxICpSDDNGpC/s400/consumidor1.png" width="400" /></a></div>
<br />
This last picture shows what happen after one consumer liberates space in the buffer, that way the next producer that try to producer can do it. In this case the producer that was blocked before (picture from above) now can produce and it does it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMIlNW1riCvUjotREry1kvbJP7LyFuOQMzJ06IxbTqcMJf9lZ_aADu0BYHdlZCyD1eojqSoqamIUGac6FZPpqm8SNgnPsEJeT71x8Eji9c0CWAQXQBMi8BuS31zFGVha_ZqANQj3HdUKvA/s1600/consumidor2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMIlNW1riCvUjotREry1kvbJP7LyFuOQMzJ06IxbTqcMJf9lZ_aADu0BYHdlZCyD1eojqSoqamIUGac6FZPpqm8SNgnPsEJeT71x8Eji9c0CWAQXQBMi8BuS31zFGVha_ZqANQj3HdUKvA/s400/consumidor2.png" width="381" /></a></div>
<br />
<br />
While the program is running the threads (producers and consumers ) behave in a similar way. As you can see the quantity of products (comestibles) is always printed and in this program the maximum of products allowed in the buffer are 10 (you probably notice that).<br />
<br />
Some notes:<br />
Instead of putting -> in the post we are putting -">" operator.<br />
Instead of using cout <<, we are using printf (don't forget this).<br />
Those changes were made because of the code was not showed <br />
in the way it supposed to be (some problems with the html).<br />
We hope those changes do not confuse you to much and we fix that problem very soon :) .<br />
<br />
<script type="text/javascript">
SyntaxHighlighter.all()
</script>collihttp://www.blogger.com/profile/03958651874427482292noreply@blogger.com10tag:blogger.com,1999:blog-777182623905430166.post-8476186964109823012011-09-11T19:19:00.000-07:002012-05-09T13:51:07.064-07:00First Theoretical PresentationThis entry is for the first theoretical presentation.<br />
The content of the entry is an explication to solve the problem <b>unbounded-buffer</b>, and a the unity test for the implement of <b>lock </b>using <b>semaphore</b>, for the project we are working with nachOS 3.4 and C++.<br />
<br />
<br />
The next code is an example of how to solve the problem unbounded buffer using three locks, one lock for producers, the second lock for consumers and the last one for protecting the access to products.<b><br />
</b><br />
<br />
<a name='more'></a><br /><br />
<pre style="background-color: #f9f9f9; border-bottom-color: rgb(47, 111, 171); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(47, 111, 171); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(47, 111, 171); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(47, 111, 171); border-top-style: dashed; border-top-width: 1px; color: black; font-family: monospace, sans-serif; line-height: 1.1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;"><i>int</i> maxProducts;
<i>int</i> products;
<b>Lock</b> *consumer<b>Lock</b>;
<b>Lock</b> *producer<b>Lock</b>;
<b>Lock</b> *changeProductsState;
<b>consumer</b>(){
<i>bool</i> hasConsumer<b>Lock</b> = <i>false</i>;
<b>while</b>(1){
<b>if</b>(!hasConsumer<b>Lock</b>){
consumer<b>Lock</b>-><b>Acquire</b>();
hasConsumer<b>Lock</b> = <i>true</i>;
}
<b>if</b>(products > 0){
changeProductsState-><b>Acquire</b>();
products--;
changeProductsState-><b>Release</b>();
consumer<b>Lock</b>-><b>Release</b>()
hasConsumer<b>Lock</b> = <i>false</i>;
}
}
}
<b>producer</b>(){
<i>bool</i> hasProducer<b>Lock</b> = <i>false</i>;
<b>while</b>(1){
<b>if</b>(!hasProducer<b>Lock</b>){
producer<b>Lock</b>-><b>Acquire</b>();
hasProducer<b>Lock</b> = <i>true</i>;
}
<b>if</b>(products < maxProducts){
changeProductsState-><b>A</b><b>cquire</b>();
products--;
changeProductsState-><b>Release</b>();
producer<b>Lock</b>-><b>Release</b>()
hasProducer<b>Lock</b> = <i>false</i>;
}
}
}</pre>
<br />
<span style="font-size: large;"><br />
</span><br />
<span style="font-size: large;">Here are some unity test used to test the implementation of the Lock using Semaphore.</span><br />
<b><br />
</b><br />
<b>Fairness<br />
</b><br />
<pre style="background-color: #f9f9f9; border-bottom-color: rgb(47, 111, 171); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(47, 111, 171); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(47, 111, 171); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(47, 111, 171); border-top-style: dashed; border-top-width: 1px; color: black; font-family: monospace, sans-serif; line-height: 1.1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;"><b>Lock</b> *<b>l</b>;
<b>Fairness</b>(){
<b>while</b>(1){
<b>l</b>-><b>Acquire</b>();
#some critical computation goes here
<b>l</b>-><b>Release</b>();
print "threadName adquired the lock"
}
}</pre>
<br />
<b>Liveness</b><b><br />
</b><br />
<pre style="background-color: #f9f9f9; border-bottom-color: rgb(47, 111, 171); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(47, 111, 171); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(47, 111, 171); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(47, 111, 171); border-top-style: dashed; border-top-width: 1px; color: black; font-family: monospace, sans-serif; line-height: 1.1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;"><b>Lock</b> *<b>l</b>;
<b>Liviness</b>(){
<b>while</b>(1){
print "threadName ask for the lock";
<b>l</b>-><b>Adquire</b>();
print "threadName acquired the lock";
<b>l</b>-><b>Release</b>();
print "threadName released the lock";
}
}</pre>
<br />
<b>Safety</b><br />
In this code we make a deadlock occur on purpose. Because two threads can not has the same lock at the same time. Eventually a deadlock it'll occur.<b><br />
</b><br />
<pre style="background-color: #f9f9f9; border-bottom-color: rgb(47, 111, 171); border-bottom-style: dashed; border-bottom-width: 1px; border-left-color: rgb(47, 111, 171); border-left-style: dashed; border-left-width: 1px; border-right-color: rgb(47, 111, 171); border-right-style: dashed; border-right-width: 1px; border-top-color: rgb(47, 111, 171); border-top-style: dashed; border-top-width: 1px; color: black; font-family: monospace, sans-serif; line-height: 1.1em; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 1em; padding-left: 1em; padding-right: 1em; padding-top: 1em;"><b>Lock</b> *<b>l2</b>;
<b>Lock</b> *<b>l3</b>;
<b>Rutine1</b>(){
<b>while</b>(1){
<b>l2</b>-><b>Acquire</b>();
<b>l3</b>-><b>Acquire</b>();
#some critical computation goes here
<b>l3</b>-><b>Release</b>();
<b>l2</b>-><b>Release</b>();
}
}
<b>Rutine2</b>(){
<b>while</b>(1){
<b>l3</b>-><b>Acquire</b>();
<b>l2</b>-><b>Acquire</b>();
#some critical computation goes here
<b>l2</b>-><b>Release</b>();
<b>l3</b>-><b>Release</b>();
}
}</pre>
<br />
<br />
<div id="__ss_9226933" style="width: 425px;">
<strong style="display: block; margin: 12px 0 4px;"><a href="http://www.slideshare.net/colli03/theoretical-presentation1nachos" title="Theoretical presentation1nachos">Theoretical presentation1nachos</a></strong><object height="355" id="__sse9226933" width="425"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=theoreticalpresentation1nachos-110912103919-phpapp01&stripped_title=theoretical-presentation1nachos&userName=colli03" />
<param name="allowFullScreen" value="true"/>
<param name="allowScriptAccess" value="always"/>
<embed name="__sse9226933" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=theoreticalpresentation1nachos-110912103919-phpapp01&stripped_title=theoretical-presentation1nachos&userName=colli03" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object><br />
<div style="padding: 5px 0 12px;">
View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/colli03">colli03</a>.</div>
</div>
<br />
Don't forget comment.<br />
<br />
Jose/Jorge/RichiAnonymousnoreply@blogger.com7