<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Nideaderedes &#187; programacion</title>
	<atom:link href="http://nideaderedes.urlansoft.com/category/programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://nideaderedes.urlansoft.com</link>
	<description>Un blog hecho por mí y para mí</description>
	<lastBuildDate>Thu, 10 Jun 2010 18:46:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Publicados ya cuatro capítulos del Curso de PHP</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/29/publicados-ya-cuatro-capitulos-del-curso-de-php/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/29/publicados-ya-cuatro-capitulos-del-curso-de-php/#comments</comments>
		<pubDate>Thu, 29 Oct 2009 17:57:23 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[mis-proyectos]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[curso php]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=977</guid>
		<description><![CDATA[Ya están publicados los primeros cuatro capítulos del curso de PHP en el Rincón del PHP.
Si tenéis dudas sobre PHP pasaos por el foro, que está nuevecito y responderé a cualquier consulta gustosamente (relacionada con PHP, claro).
]]></description>
			<content:encoded><![CDATA[<p>Ya están publicados los primeros cuatro capítulos del <a href="http://elrincondelphp.com/cursophp/curso" title="Curso de PHP">curso de PHP</a> en el <a href="http://elrincondelphp.com/" title="Web dedicada a la programación en PHP">Rincón del PHP</a>.</p>
<p>Si tenéis dudas sobre PHP pasaos por el <a href="http://elrincondelphp.com/foros/" title="Foro de PHP">foro</a>, que está nuevecito y responderé a cualquier consulta gustosamente (relacionada con PHP, claro).</p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/29/publicados-ya-cuatro-capitulos-del-curso-de-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procesos en C: Crear un nuevo proceso con fork()</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/26/procesos-en-c-crear-un-nuevo-proceso-con-fork/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/26/procesos-en-c-crear-un-nuevo-proceso-con-fork/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 07:00:22 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[fork]]></category>
		<category><![CDATA[procesos]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=933</guid>
		<description><![CDATA[Siguiendo con los artículos sobre procesos voy a poner aquí un sencillo ejemplo para ilustrar el funcionamiento de la función fork().
Esta función es la que se encarga de crear un nuevo proceso dentro de un proceso. El nuevo proceso creado es una copia exacta del original, con la única diferencia que cada uno de ellos [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo con los artículos sobre procesos voy a poner aquí un sencillo ejemplo para ilustrar el funcionamiento de la función fork().</p>
<p>Esta función es la que se encarga de crear un nuevo proceso dentro de un proceso. El nuevo proceso creado es una copia exacta del original, con la única diferencia que cada uno de ellos tiene su propio identificador de proceso (pid).</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> pid;
&nbsp;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PADRE: Soy el proceso padre y mi pid es: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, getpid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	pid <span style="color: #339933;">=</span> fork<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// En cuanto llamamos a fork se crea un nuevo proceso. En el proceso</span>
	<span style="color: #666666; font-style: italic;">// padre 'pid' contendrá el pid del proceso hijo. En el proceso hijo</span>
	<span style="color: #666666; font-style: italic;">// 'pid' valdrá 0. Eso es lo que usamos para distinguir si el código</span>
	<span style="color: #666666; font-style: italic;">// que se está ejecutando pertenece al padre o al hijo.</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pid<span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// Este es el proceso padre</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PADRE: Soy el proceso padre y mi pid sigue siendo: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, getpid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;PADRE: Mi hijo tiene el pid: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, pid<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #666666; font-style: italic;">// Proceso hijo</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;HIJO: Soy el proceso hijo y mi pid es: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, getpid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;HIJO: mi padre tiene el pid: %d<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, getppid<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>En un próximo post explicaré cómo convertir el proceso hijo en un nuevo proceso totalmente diferente (con el conjunto de funciones &#8216;exec&#8217;). Esto nos permitirá lanzar un programa desde dentro de otro.</p>
<hr/>
<p>¿Necesitas ayuda con algún trabajo de clase? Entra en <a href="http://buscoprofe.com" title="Ayuda con trabajos de clase">BuscoProfe.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/26/procesos-en-c-crear-un-nuevo-proceso-con-fork/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>El Rincón del PHP &#8211; Web dedicada a la programación en PHP</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/25/el-rincon-del-php-web-dedicada-a-la-programacion-en-php/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/25/el-rincon-del-php-web-dedicada-a-la-programacion-en-php/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 09:58:23 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[mis-proyectos]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[foros]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=973</guid>
		<description><![CDATA[Siguiendo con nuestros contínuos lanzamientos   hace un par de días pusimos en marcha la nueva web del Rincón del PHP.
La idea de la web es ser un punto en el que poder encontrar información sobre PHP, cursos y un foro donde podamos conocernos, compartir ideas y exponer dudas.
Entra en el Rincón del PHP, [...]]]></description>
			<content:encoded><![CDATA[<p>Siguiendo con nuestros contínuos lanzamientos <img src='http://nideaderedes.urlansoft.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  hace un par de días pusimos en marcha la nueva web del <a href="http://elrincondelphp.com" title="Foros y cursos de PHP">Rincón del PHP</a>.</p>
<p>La idea de la web es ser un punto en el que poder encontrar información sobre PHP, cursos y un foro donde podamos conocernos, compartir ideas y exponer dudas.</p>
<p>Entra en el <a href="http://elrincondelphp.com" title="Foros y cursos de PHP">Rincón del PHP</a>, los foros están nuevecitos ¿te animas a estrenarlos?</p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/25/el-rincon-del-php-web-dedicada-a-la-programacion-en-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Procesos en C: Ejemplo de un sencillo cronómetro con SIGALRM</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/19/procesos-en-c-ejemplo-de-un-sencillo-cronometro/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/19/procesos-en-c-ejemplo-de-un-sencillo-cronometro/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 23:45:35 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[procesos]]></category>
		<category><![CDATA[señales]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=919</guid>
		<description><![CDATA[Continuando con el artículo de la semana pasada sobre procesos en C hoy os dejo aquí un sencillo ejemplo de un cronómetro:

// Para las funciones pause y alarm:
#include &#60;unistd.h&#62;
// Para las constantes SIGALRM y similares
#include &#60;signal.h&#62;
&#160;
#include &#60;stdio.h&#62;
&#160;
// Esta es la función que se va a ejecutar cada vez que se reciba la
// señal SIGALRM
void contar_segundos&#40;&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Continuando con el artículo de la semana pasada sobre <a href="http://nideaderedes.urlansoft.com/2009/10/13/procesos-en-c-senales-sigint/">procesos en C</a> hoy os dejo aquí un sencillo ejemplo de un cronómetro:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #666666; font-style: italic;">// Para las funciones pause y alarm:</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #666666; font-style: italic;">// Para las constantes SIGALRM y similares</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Esta es la función que se va a ejecutar cada vez que se reciba la</span>
<span style="color: #666666; font-style: italic;">// señal SIGALRM</span>
<span style="color: #993333;">void</span> contar_segundos<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Usamos static para que se conserve el valor de &quot;segundos&quot;</span>
	<span style="color: #666666; font-style: italic;">// entre cada llamada a la función</span>
	<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> segundos<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span>;
&nbsp;
	segundos<span style="color: #339933;">++</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Han pasado %d segundos.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>, segundos<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Asociamos la señal SIGALRM a la función contar_segundos</span>
	signal<span style="color: #009900;">&#40;</span>SIGALRM, contar_segundos<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// Ponemos en marcha un bucle</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Establecemos una alarma para dentro de un segundo</span>
		alarm<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #666666; font-style: italic;">// Pausamos la ejecución del programa para que </span>
		<span style="color: #666666; font-style: italic;">// se quede esperando a recibir una señal.</span>
		pause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<hr/>
<p>¿Necesitas ayuda con algún trabajo de clase? Entra en <a href="http://buscoprofe.com" title="Ayuda con trabajos de clase">BuscoProfe.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/19/procesos-en-c-ejemplo-de-un-sencillo-cronometro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Procesos en C: Señales (SIGINT)</title>
		<link>http://nideaderedes.urlansoft.com/2009/10/13/procesos-en-c-senales-sigint/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/10/13/procesos-en-c-senales-sigint/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 07:00:51 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[procesos]]></category>
		<category><![CDATA[señales]]></category>
		<category><![CDATA[SIGINT]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=912</guid>
		<description><![CDATA[Una breve introducción a los procesos en C y las señales. Señal SIGINT.]]></description>
			<content:encoded><![CDATA[<p>Desde hace un tiempo tengo la idea de escribir sobre el tema de procesos y señales en C.</p>
<p>Las señales se usan para la comunicación entre procesos y manipularlos. Un ejemplo muy conocido de señal es la señal SIGINT, que se envía cuando el usuario pulsa CTRL+C durante la ejecución de un programa. Cuando el programa que estamos ejecutando recibe esta señal finalizará su ejecución.</p>
<p>En el siguiente ejemplo vamos a ver cómo podemos hacer para que el programa realice alguna acción especial cuando el usuario pulse CTRL+C. La acción a ejecutar va a ser mostrar el mensaje: &#8220;¿Por qué me interrumpes?&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #666666; font-style: italic;">// Para las funciones pause y alarm:</span>
<span style="color: #339933;">#include &lt;unistd.h&gt;</span>
<span style="color: #666666; font-style: italic;">// Para las constantes SIGALRM y similares</span>
<span style="color: #339933;">#include &lt;signal.h&gt;</span>
&nbsp;
<span style="color: #339933;">#include &lt;stdio.h&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Esta función es la que vamos a usar como controlador de la señal SIGINT</span>
<span style="color: #993333;">void</span> despedida<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;¿Por qué me interrumpes?<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	raise<span style="color: #009900;">&#40;</span>SIGTERM<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Asociamos la señal SIGINT con la funcion &quot;senal&quot;</span>
	signal<span style="color: #009900;">&#40;</span>SIGINT, despedida<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #666666; font-style: italic;">// Comenzamos un bucle que hará que el programa muestre sin</span>
	<span style="color: #666666; font-style: italic;">// parar el mensaje &quot;Nada nuevo por aquí&quot;</span>
	<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Nada nuevo por aquí.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>En este programa, cuando el usuario pulse CTRL+C, en lugar de cerrarse directamente, se ejecutará la función que hemos asociado con esta señal (la funcion despedida).</p>
<p>La función despedida muestra el mensaje &#8220;¿Por qué me interrumpes?&#8221; y genera la señal SIGTERM (&#8221;raise&#8221; envía una señal al propio proceso). Si no hiciéramos esto el proceso no se detendría nunca (hasta que lo &#8220;matemos&#8221; con kill). Si te aburres haz la prueba con esta funcion:</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">void</span> despedida<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;¿Por qué me interrumpes?<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Otra posibilidad es usar la función signal de nuevo para indicar al proceso que use la acción por defecto de SIGINT (SIG_DFL &#8211; Signal Default):</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">void</span> despedida<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;¿Por qué me interrumpes?<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	signal<span style="color: #009900;">&#40;</span>SIGINT, SIG_DFL<span style="color: #009900;">&#41;</span>; <span style="color: #666666; font-style: italic;">// Indicamos al programa que use la acción por defecto</span>
	raise<span style="color: #009900;">&#40;</span>SIGINT<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>¿Pero por qué no podemos simplemente llamar a raise(SIGINT);?</p>
<p>Se podría pensar que bastaría con llamar a raise(SIGINT):</p>

<div class="wp_syntax"><div class="code"><pre class="c"><span style="color: #993333;">void</span> despedida<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;¿Por qué me interrumpes?<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	<span style="color: #000066;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;------------------------<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span>;
	raise<span style="color: #009900;">&#40;</span>SIGINT<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>El problema es que la señal SIGINT va a ser procesada por la función &#8220;despedida&#8221;. De esta forma, cuando pulsemos CTRL+C, se llamará a la función despedida. La función despedida genera de nuevo la señal SIGINT, que va a ser procesada de nuevo por ella misma. El resultado es que cuando pulsamos CTRL+c el proceso comenzará a ejecutar una y otra vez la función despedida mostrando el mensaje &#8220;¿Por qué me interrumpes?&#8221; sin parar.</p>
<p>¿Por qué? Cada vez que se pulse CTRL+C se ejecuta la función &#8220;despedida&#8221; en lugar de ejecutarse la acción por defecto (cerrar el programa).</p>
<hr/>
<p>¿Necesitas ayuda con algún trabajo de clase? Entra en <a href="http://buscoprofe.com" title="Ayuda con trabajos de clase">BuscoProfe.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/10/13/procesos-en-c-senales-sigint/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducción a Bash: control de flujo en nuestro script (if/else)</title>
		<link>http://nideaderedes.urlansoft.com/2009/05/25/introduccion-a-bash-control-de-flujo-en-nuestro-script/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/05/25/introduccion-a-bash-control-de-flujo-en-nuestro-script/#comments</comments>
		<pubDate>Mon, 25 May 2009 07:00:22 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=870</guid>
		<description><![CDATA[Hoy vamos a añdadir un poco más de salsa a nuestra introdicción a Bash. Vamos a ver cómo funciona el if/else.
La estructura de un if/else en bash es la siguiente:

if &#91; condicion &#93;; then
      ...
else
      ...
fi

(el &#8220;else&#8221; es opcional).
Ojo, los corchetes deben ir siempre separados [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy vamos a añdadir un poco más de salsa a nuestra introdicción a Bash. Vamos a ver cómo funciona el if/else.</p>
<p>La estructura de un if/else en bash es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> condicion <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
      ...
<span style="color: #000000; font-weight: bold;">else</span>
      ...
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>(el &#8220;else&#8221; es opcional).</p>
<p>Ojo, los corchetes deben ir siempre separados de la condición por un espacio.</p>
<h2>Comparaciones aritméticas:</h2>
<p>Aquí tenéis una lista de comparaciones que se pueden hacer entre números.</p>
<ul>
<li> -lt : menor que (less than)</li>
<li>-gt : mayor que (greater than)</li>
<li>-le : menor o igual (less or equal)</li>
<li>-ge : mayor o igual (greater or equal)</li>
<li>-eq : igual a (equal)</li>
<li>-ne : distinto de (not equal)</li>
</ul>
<h2>Compraraciones con cadenas</h2>
<ul>
<li> = : igual</li>
<li> != : distinto</li>
<li>&lt; : menor que</li>
<li>&gt; : mayor que</li>
<li>-n c1 : se cumple si la cadena c1 no está vacía</li>
<li>-z s1 : se cumple si la cadena c1 está vacía</li>
</ul>
<h2>If anidados</h2>
<p>Desde luego, se pueden usar if/else dentro de otros if/else, se pueden anidar sin problemas.</p>
<h2>Ejemplo</h2>
<p>Y para ilustrar todo esto vamos a ver un sencillo ejemplo que espera que le pasemos una palabra como parámetro:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> -eq <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Dime algo, por favor&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> $<span style="color: #000000;">1</span> = <span style="color: #ff0000;">'hola'</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Hola! que tal?&quot;</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No te entiendo, solo entiendo la palabra 'hola'&quot;</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Si lo guardamos en un fichero llamado if.sh y le damos permisos de ejecución (chmod +x if.sh) esto es lo que responderá dependiendo de qué parámetros usemos:</p>
<pre>
$ ./if.sh
Dime algo, por favor
</pre>
<pre>
$ ./if.sh nada
No te entiendo, solo entiendo la palabra 'hola'
</pre>
<pre>
$ ./if.sh hola
Hola! que tal?
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/05/25/introduccion-a-bash-control-de-flujo-en-nuestro-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress: listar subpáginas dentro de una página</title>
		<link>http://nideaderedes.urlansoft.com/2009/05/18/wordpress-listar-subpaginas-dentro-de-una-pagina/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/05/18/wordpress-listar-subpaginas-dentro-de-una-pagina/#comments</comments>
		<pubDate>Mon, 18 May 2009 07:00:47 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[programacion]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=852</guid>
		<description><![CDATA[Si quieres que cuando se visualice una página se muestren también sus páginas &#8220;hijas&#8221; puedes usar el siguiente código en tu plantilla:

&#60;?php
  if&#40;$post-&#62;post_parent&#41;
  $children = wp_list_pages&#40;&#34;title_li=&#38;child_of=&#34;.$post-&#62;post_parent.&#34;&#38;echo=0&#34;&#41;;
  else
  $children = wp_list_pages&#40;&#34;title_li=&#38;child_of=&#34;.$post-&#62;ID.&#34;&#38;echo=0&#34;&#41;;
  if &#40;$children&#41; &#123; ?&#62;
  &#60;ul&#62;
  &#60;?php echo $children; ?&#62;
  &#60;/ul&#62;
  &#60;?php &#125; ?&#62;

Sacado del codex de [...]]]></description>
			<content:encoded><![CDATA[<p>Si quieres que cuando se visualice una página se muestren también sus páginas &#8220;hijas&#8221; puedes usar el siguiente código en tu plantilla:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000033;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">else</span>
  <span style="color: #000033;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000033;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000033;">$children</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">echo</span> <span style="color: #000033;">$children</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Sacado del <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages">codex de WordPress</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/05/18/wordpress-listar-subpaginas-dentro-de-una-pagina/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Code Igniter: llamar a un controlador desde consola o desde otro fichero.php</title>
		<link>http://nideaderedes.urlansoft.com/2009/04/30/code-igniter-llamar-a-un-controlador-desde-consola-o-desde-otro-ficherophp/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/04/30/code-igniter-llamar-a-un-controlador-desde-consola-o-desde-otro-ficherophp/#comments</comments>
		<pubDate>Thu, 30 Apr 2009 07:00:25 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[code igniter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=821</guid>
		<description><![CDATA[Si has trabajado con Code Igniter encontrarás este &#8220;truquillo&#8221; de mucha utilidad. Te permitirá llamar a un controlador desde consola o desde otro fichero PHP. Por ejemplo:
1) Supón que tienes una tarea (en un cron) que tiene que llamar a un controlador de tu aplicación Code Igniter. Supongamos que tienes un controlador que se llama [...]]]></description>
			<content:encoded><![CDATA[<p>Si has trabajado con <a href="http://www.codeigniter.com/">Code Igniter</a> encontrarás este &#8220;truquillo&#8221; de mucha utilidad. Te permitirá llamar a un controlador desde consola o desde otro fichero PHP. Por ejemplo:</p>
<p>1) Supón que tienes una tarea (en un <a href="http://es.wikipedia.org/wiki/Cron_(unix)">cron</a>) que tiene que llamar a un controlador de tu aplicación Code Igniter. Supongamos que tienes un controlador que se llama &#8217;saludar&#8217; y quieres llamar a la función &#8216;decir_hola&#8217; de ese controlador. No puedes hacer la llamada así:</p>
<pre>php /var/www/saludar/decir_hola</pre>
<p>ni:</p>
<pre>php /var/www/index.php/saludar/decir_hola</pre>
<p>(pruébalo)</p>
<p>2) También es posible que necesites recibir parámetros $_GET pero, por ejemplo, no sabes en el orden en el que te los van a enviar.</p>
<p>En ambos casos puedes crear un fichero llamado, por ejemplo, redirigir.php con el contenido siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Recoger parámetros o cualquier otra tarea previa que necesites antes de llamar al controlador</span>
<span style="color: #339933;">...</span>
<span style="color: #666666; font-style: italic;">// Fin de tareas previas</span>
&nbsp;
<span style="color: #000033;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">'saludar/decir_hola'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>o incluso, podemos pasarle parámetros desde la consola:</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000033;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span>    <span style="color: #339933;">=</span> <span style="color: #000033;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>(Si usas el fichero .htaccess no olvides añadir este fichero redirigir.php para que se pueda ejecutar).</p>
]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/04/30/code-igniter-llamar-a-un-controlador-desde-consola-o-desde-otro-ficherophp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Curso de PHP: Ejercicios de cadenas y funciones</title>
		<link>http://nideaderedes.urlansoft.com/2009/04/29/curso-de-php-ejercicios-de-cadenas-y-funciones/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/04/29/curso-de-php-ejercicios-de-cadenas-y-funciones/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 07:00:24 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[curso php]]></category>
		<category><![CDATA[ejercicios]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=828</guid>
		<description><![CDATA[Dado que llevo bastante tiempo impartiendo cursos de PHP en Bilbao ya va siendo hora de poner un poco de orden y actualizar los ejercicios.
Según los vaya poniendo &#8220;bonitos&#8221; los iré publicando aquí.
En esta primera tanda pondré algunos ejercicios de cadenas y funciones que servirán de repaso a mis alumnos. A ver si se animan [...]]]></description>
			<content:encoded><![CDATA[<p>Dado que llevo bastante tiempo impartiendo <a href="http://www.elrincondelc.com/nuevorincon/index.php?pag=info&#038;sec=cursophppresencialbilbao">cursos de PHP en Bilbao</a> ya va siendo hora de poner un poco de orden y actualizar los ejercicios.</p>
<p>Según los vaya poniendo &#8220;bonitos&#8221; los iré publicando aquí.</p>
<p>En esta primera tanda pondré algunos ejercicios de cadenas y funciones que servirán de repaso a mis alumnos. A ver si se animan algunos a hacerlos, que haciendo el esfuerzo de resolverlos es como se aprende, no mirando cómo los resuelve otro (este es un pequeño tirón de orejas para un par de personas <img src='http://nideaderedes.urlansoft.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  ).</p>

<div class="wp_syntax"><div class="code"><pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * Para los siguientes ejercicios se deben/pueden usar las siguientes funciones:
 * 
 * - substr($cadena, $comienzo, $longitud);
 * 		Extrae una subcadena de una cadena:
 * 		$cadena - es la cadena de la que queremos sacar una subcadena
 * 		$comienzo - es la posición a partir de la que empezamos a extraer. El primer carácter
 * 		está en la posición 0.
 * 		$longitud - con este parámetro indicamos la longitud de la cadena. Es opcional, si
 * 		no lo ponemos nos cogerá todo desde el comienzo que hemos especificado hasta el final.
 * 
 * - strlen($cadena);
 * 		Cuenta el número de caracteres que tiene la cadena.
 * 
 * - strtoupper($cadena);
 * 		Convierte una cadena en mayúsculas.
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 1:
 * 
 * Escribir una función que convierta la primera letra de una cadena en mayúsculas.
 * 
 */</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 1&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: Gorka</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GORKA'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: GORKA</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: Gorka</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 2:
 * 
 * ¿Daría algún error si usamos una cadena de una sola letra? ¿Sabrías por qué?
 * 
 */</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 2&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'G'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 3:
 * 
 * ¿Funcionaría bien la siguiente función? Por el nombre es evidente que no pero
 * ¿por qué? 
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> corregir_primera_letra_version_mala<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000033;">$letra</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$letra</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$letra</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$resto</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000033;">$cadena_corregida</span> <span style="color: #339933;">=</span> <span style="color: #000033;">$letra</span> <span style="color: #339933;">.</span> <span style="color: #000033;">$cadena</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000033;">$cadena_corregida</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 4:
 * 
 * Crear una función que coja una cadena, ponga la primera en mayúsculas y
 * el resto en minúsculas.
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> corregir_mayusculas<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 4&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: Gorka</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'GORKA'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: Gorka</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> corregir_primera_letra<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: Gorka</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 5:
 * 
 * Escribir una función que cuente el número de 'a' minúsculas que hay en una frase.
 * (usar for en lugar de foreach)
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> contar_letra_a<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 5&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_letra_a<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_letra_a<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'La bala mata la vaca'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: 8</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_letra_a<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'El oso osó asir a la osa'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: 4</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 6: (este es para nota)
 * 
 * Escribir una función que cuente el número de mayúsculas de una cadena.
 * 
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> contar_mayusculas<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 6&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_mayusculas<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'gorka'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: 0</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_mayusculas<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'La bala mata la vaca'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// --&gt; debe mostrar: 1</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * Ejercicio 7: (este es para nota)
 * 
 * Si usamos una cadena como la que viene a continuación ¿contará bien? ¿por qué?
 * ¿cómo corregirías la función? (pista: problemas con la letra 'Ñ')
 * 
 */</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">'&lt;h1&gt;Ejercicio 7&lt;/h1&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> contar_mayusculas<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'El Ñoño Niñato Ñoñeaba sin parar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> contar_mayusculas_corregida<span style="color: #009900;">&#40;</span><span style="color: #000033;">$cadena</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">echo</span> contar_mayusculas_corregida<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'El Ñoño Niñato Ñoñeaba sin parar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">echo</span> <span style="color: #0000ff;">&quot;&lt;br/&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/04/29/curso-de-php-ejercicios-de-cadenas-y-funciones/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: listar los usuarios de un ordenador</title>
		<link>http://nideaderedes.urlansoft.com/2009/04/24/bash-listar-los-usuarios-de-un-ordenador/</link>
		<comments>http://nideaderedes.urlansoft.com/2009/04/24/bash-listar-los-usuarios-de-un-ordenador/#comments</comments>
		<pubDate>Fri, 24 Apr 2009 07:00:54 +0000</pubDate>
		<dc:creator>gorkau</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[programacion]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://nideaderedes.urlansoft.com/?p=813</guid>
		<description><![CDATA[Dado que últimamente estoy haciendo bastantes cosillas con bash voy a poner una serie de &#8220;truquillos&#8221; aquí.
NOTA: El ejemplo que propongo aquí es un copia/pega de un script que creé para un servidor y una finalidad muy concretas.
En cierto servidor necesitaba tener un listado de los usuarios. Una posibilidad puede ser ir al directorio home [...]]]></description>
			<content:encoded><![CDATA[<p>Dado que últimamente estoy haciendo bastantes cosillas con bash voy a poner una serie de &#8220;truquillos&#8221; aquí.</p>
<p>NOTA: El ejemplo que propongo aquí es un copia/pega de un script que creé para un servidor y una finalidad muy concretas.</p>
<p>En cierto servidor necesitaba tener un listado de los usuarios. Una posibilidad puede ser ir al directorio home y ver allí los usuarios (cada usuario tendrá un directorio &#8216;home&#8217;).</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">for</span> directorio <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/*</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> .<span style="color: #000000; font-weight: bold;">/</span>actualizador_cada.<span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #007800;">$directorio</span>.
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>dará como resultado: </p>
<pre>
/home/gorka
/home/alumno
/home/lost+found
/home/mysql
...
</pre>
<p>Si queremos que no nos muestre &#8216;/home&#8217; podemos eliminar esa parte de cada directorio usando una subcadena:</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${directorio:6}</span></pre></div></div>

<p>(esto mostrará una subcadena de $directorio desde la posición 6 hasta el final)</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #000000; font-weight: bold;">for</span> directorio <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/*</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${directorio:6}</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>dará como resultado: </p>
<pre>
gorka
alumno
lost+found
mysql
...
</pre>
<p>NOTA: esto funciona en un sistema en el que los usuarios tengan directorios &#8216;home&#8217; iguales a su nombres de usuario.</p>
<p>Seguramente verás que hay algunos usuarios que no te interesan (en mi caso sólo me interesaban los usuarios &#8220;reales&#8221;) así que añadí unas líneas para eliminar los que no interesaban (mysql, lost+found, etc&#8230;):</p>

<div class="wp_syntax"><div class="code"><pre class="bash"><span style="color: #007800;">usuarios_no_validos=</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #ff0000;">'mysql'</span> <span style="color: #ff0000;">'lost+found'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">for</span> directorio <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/*</span>; <span style="color: #000000; font-weight: bold;">do</span>
	<span style="color: #007800;">valido=</span><span style="color: #000000;">1</span>
	<span style="color: #007800;">usuario=</span><span style="color: #800000;">${directorio:6}</span>
	<span style="color: #000000; font-weight: bold;">for</span> usuario_no_valido <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #800000;">${usuarios_no_validos[@]}</span>; <span style="color: #000000; font-weight: bold;">do</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$usuario_no_valido</span> = <span style="color: #007800;">$usuario</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
			<span style="color: #007800;">valido=</span><span style="color: #000000;">0</span>
		<span style="color: #000000; font-weight: bold;">fi</span>
	<span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$valido</span> -eq <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$usuario</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://nideaderedes.urlansoft.com/2009/04/24/bash-listar-los-usuarios-de-un-ordenador/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
