Академический Документы
Профессиональный Документы
Культура Документы
SISTEMAS OPERATIVOS
GUIA DE LABORATORIO
ECP 1 de 8
I.
II.
TEMA :
PROGRAMACION EN LINUX
OBJETIVOS DE LA PRACTICA
El estudiante al finalizar la prctica ser capaz de:
1. Utilizar el sistema operativo Linux como una plataforma de desarrollo de
aplicaciones
2. Escribe programas utilizando el lenguaje de programacin C para el sistema
operativo Linux
III.
TRABAJO PREPARATORIO
Para un trabajo con mejores resultados, es imprescindible que el estudiante:
1. Tenga familiaridad con el sistema operativo Linux
IV.
MATERIALES NECESARIOS.
Para el desarrollo de la presente prctica es necesario contar con:
1. Sistema operativo Linux
2. Compilador gcc instalado
3. Editor de textos
V.
MARCO TEORICO.
PROGRAMACION EN LINUX
Se suele creer que en el sistema operativo Linux solo se puede programar el C. Si bien
es cierto que gran parte del sistema operativo Linux, est escrito en C, as como la
mayora de las aplicaciones; C no es la nica opcin disponible en Linux.
Existe un vasto nmero de lenguajes de programacin para Linux y muchos de ellos
estn disponibles en forma gratuita en diversos sitios Web. En el siguiente cuadro se
muestra algunos lenguajes de programacin disponibles para el programador de Linux:
Ada
C++
Eiffel
Forth
Fortran
Icon
Java
JavaScript
Lisp
Modula 2
Modula 3
Oberon
Objective C
Pascal
Perl
PostScript
Prolog
Python
Scheme
Smalltalk
Tcl/Tk
Basic .Net
C#
PROGRAMAS EN LINUX
Las aplicaciones en Linux se representan por dos tipos especiales de archivos:
ejecutables y scripts. Los archivos ejecutables son programas que pueden ser ejecutados
directamente por el computador y se corresponden a los archivos .exe del DOS. Los
scripts son colecciones de instrucciones que otro programa, un intrprete, debe seguir.
Estos se corresponden con los archivos .bat del DOS.
Linux no requiere que los ejecutables o los scripts tengan un nombre de archivo
especfico. Los atributos del sistema de archivos se utilizan para indicar que un archivo
es un programa que se puede ejecutar.
OBTENCION DE AYUDA
Para obtener ayuda sobre algn programa o sentencia utilizamos la orden man
utilizando la siguiente sintaxis:
man <nombre de programa o sentencia>
Por ejemplo, para obtener ayuda sobre el compilador gcc, la orden sera:
man gcc
Esta orden nos mostrar por pantalla la ayuda del gcc; la cual debe ser similar a la
siguiente:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
GCC(1)
GNU Tools
GCC(1)
NAME
gcc, g++ - GNU project C and C++ Compiler (egcs-1.1.2)
SYNOPSIS
gcc [ option | filename ]...
g++ [ option | filename ]...
WARNING
The information in this man page is an extract from the
full documentation of the GNU C compiler, and is limited
to the meaning of the options.
This man page is not kept up to date except when volunteers want to maintain it.
If you find a discrepancy
between the man page and the software, please check the
Info file, which is the authoritative documentation.
If we find that the things in this man page that are out
of date cause significant confusion or complaints, we will
stop distributing the man page. The alternative, updating
the man page when we update the Info file, is impossible
because the rest of the work of maintaining GNU CC leaves
us no time for that. The GNU project regards man pages as
obsolete and should not let them take time away from other
things.
For complete and current documentation, refer to the Info
file 'gcc' or the manual Using and Porting GNU CC (for
version 2.0). Both are made from the Texinfo source file
gcc.texinfo.
...
Al recorrer el archivo de ayuda, utilizamos la barra espaciadora para leer la siguiente
pgina, la tecla Enter para leer la siguiente lnea, y la tecla q para salir de la ayuda.
VI.
DESARROLLO DE LA PRACTICA
1.
Solucin:
//
//
//
//
//
Nombre
Proposito
Autor
FCreacion
FModificacion
:
:
:
:
:
Cuadrado
Calcula el cuadrado de un numero
Edwin Carrasco
05/09/2007
--
#include<stdio.h>
main ()
{
//Variables
int numero;
float resultado;
//Indicar que hace el programa
puts("ESTE PROGRAMA CALCULA EL CUADRADO DE UN NUMERO");
//Leer datos
printf("Ingrese un numero: ");
scanf("%d",&numero);
//Procesar
resultado = numero * numero;
//Mostrar resultados
printf("El cuadrado de %d es %f\n", numero, resultado);
}
2.
Escriba un programa que lea N nmeros del teclado y muestre el promedio de estos
Solucion:
//
//
//
//
//
Nombre
Proposito
Autor
FCreacion
FModificacion
:
:
:
:
:
#include<stdio.h>
main ()
{
//Variables
float numero=0;
float acumulador=0;
int contador=0;
float promedio=0;
promedio
calcula el promedio de N numeros
Edwin Carrasco
05/09/2007
--
3.
Solucion:
// Nombre
// Proposito
:
:
// Autor
// FCreacion
// FModificacion
:
:
:
#include<stdio.h>
main ()
{
//Variables
int N = 10;
int arreglo[N];
int numero;
int i=0;
double suma=0;
sumaArreglo
calcula la suma de los elementos de
un arreglo
Edwin Carrasco
05/09/2007
--
//Mostrar resultados
printf("La suma de los elementos del arreglo es %f \n",
suma);
}
VII.
EJERCICIOS PROPUESTOS.
1.
Escriba un programa en C, que lea un nombre por el del teclado y muestre por
pantalla un mensaje de bienvenida, de acuerdo al siguiente formato:
Ingrese su nombre:
Juan
Juan, bienvenido a Linux
2.
3.
4.
5.
6.
VIII.
BIBLIOGRAFIA
1.
2.
3.
4.
5.
6.
7.