add doxygen docs
This commit is contained in:
BIN
report/Enunciado - ProyectoSemestral.pdf
Normal file
BIN
report/Enunciado - ProyectoSemestral.pdf
Normal file
Binary file not shown.
94
report/Informe.tex
Normal file
94
report/Informe.tex
Normal file
@@ -0,0 +1,94 @@
|
||||
\title{Proyecto Semestral}
|
||||
\author{}
|
||||
\date{\today}
|
||||
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\usepackage[utf8]{inputenc} %\ This allows spanish tildes
|
||||
\usepackage[spanish]{babel}
|
||||
\usepackage{array}
|
||||
\usepackage{adjustbox}
|
||||
\usepackage{titling}
|
||||
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm,letterpaper]{geometry}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{listings}
|
||||
\usepackage{xcolor}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{lmodern}
|
||||
|
||||
\usepackage{mathptmx}
|
||||
|
||||
\newcommand{\Quad}{\hspace*{1em}}
|
||||
|
||||
\lstdefinestyle{freefempp}{
|
||||
language=C,
|
||||
basicstyle=\scriptsize\ttfamily,
|
||||
commentstyle=\itshape\color{gray},
|
||||
keywordstyle=\color{blue},
|
||||
numberstyle=\color{red},
|
||||
stringstyle=\color{red},
|
||||
identifierstyle=\color{violet},
|
||||
showstringspaces=false,
|
||||
%float,
|
||||
%frame=single,
|
||||
%numbers=left
|
||||
}
|
||||
|
||||
\lstset{
|
||||
basicstyle=\scriptsize\ttfamily,
|
||||
columns=flexible,
|
||||
breaklines=true,
|
||||
inputencoding=utf8,
|
||||
extendedchars=true,
|
||||
literate={á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1 {ñ}{{\~n}}1 {Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1 {Ñ}{{\~N}}1,
|
||||
style=freefempp
|
||||
}
|
||||
|
||||
\usepackage{hyperref}
|
||||
\hypersetup{colorlinks=true,allcolors=black,pdftitle={Proyecto Semestral}}
|
||||
\usepackage{hypcap}
|
||||
|
||||
\pretitle{%
|
||||
\begin{center}
|
||||
\LARGE
|
||||
\includegraphics[width=4cm]{ubblogo.png}\\[\bigskipamount]
|
||||
\Large
|
||||
\textbf{Sistemas Operativos}\\[\smallskipamount]
|
||||
}
|
||||
|
||||
\posttitle{\end{center}}
|
||||
|
||||
\begin{document}
|
||||
\hypersetup{pageanchor=false}
|
||||
\clearpage\maketitle
|
||||
\thispagestyle{empty}
|
||||
|
||||
\begin{flushright}
|
||||
\textbf{Integrantes:}\\
|
||||
Christopher Cromer
|
||||
\end{flushright}
|
||||
|
||||
\begin{flushright}
|
||||
\textbf{Profesor:}\\
|
||||
Carlos Faúndez
|
||||
\end{flushright}
|
||||
|
||||
\newpage
|
||||
|
||||
\clearpage
|
||||
\thispagestyle{empty}
|
||||
\tableofcontents
|
||||
|
||||
\newpage
|
||||
\hypersetup{pageanchor=true}
|
||||
\pagenumbering{arabic}
|
||||
|
||||
\include{sections/introduccion}
|
||||
|
||||
\include{sections/funcionamiento}
|
||||
|
||||
\include{sections/codigo}
|
||||
|
||||
\include{sections/conclusiones}
|
||||
|
||||
\end{document}
|
16
report/Makefile
Normal file
16
report/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
all: report
|
||||
|
||||
report:
|
||||
# we do this twice to make sure the toc is updated
|
||||
pdflatex -synctex=1 -interaction=nonstopmode "Informe.tex"
|
||||
pdflatex -synctex=1 -interaction=nonstopmode "Informe.tex"
|
||||
|
||||
clean:
|
||||
rm -f Informe.pdf
|
||||
find . -type f -name '*.log' -exec rm {} +
|
||||
find . -type f -name '*.toc' -exec rm {} +
|
||||
find . -type f -name '*.gz' -exec rm {} +
|
||||
find . -type f -name '*.aux' -exec rm {} +
|
||||
find . -type f -name '*.out' -exec rm {} +
|
||||
|
||||
.PHONY: all report clean
|
9
report/code/builtins.txt
Normal file
9
report/code/builtins.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
void run_builtin(StringArray *args) {
|
||||
if (strcmp(args->array[0], "exit") == 0) {
|
||||
exit_shell(args);
|
||||
}
|
||||
}
|
||||
|
||||
void exit_shell(StringArray *args) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
33
report/code/environ.txt
Normal file
33
report/code/environ.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
typedef struct {
|
||||
StringArray *keys;
|
||||
StringArray *values;
|
||||
size_t size;
|
||||
} ArrayList;
|
||||
|
||||
void set_array_list(ArrayList *array_list, char *key, char *value) {
|
||||
if (array_list->keys == NULL) {
|
||||
array_list->keys = create_string_array();
|
||||
array_list->values = create_string_array();
|
||||
}
|
||||
for (size_t i = 0; i < array_list->size; i++) {
|
||||
if (strcmp(array_list->keys->array[i], key) == 0) {
|
||||
array_list->values->array[i] = realloc(array_list->values->array[i], strlen(value) * sizeof(char *));
|
||||
strcpy(array_list->values->array[i], value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
insert_string_array(array_list->keys, key);
|
||||
insert_string_array(array_list->values, value);
|
||||
array_list->size++;
|
||||
}
|
||||
|
||||
char *get_array_list(ArrayList *array_list, char *key) {
|
||||
if (array_list->keys != NULL) {
|
||||
for (size_t i = 0; i < array_list->size; i++) {
|
||||
if (strcmp(array_list->keys->array[i], key) == 0) {
|
||||
return array_list->values->array[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
20
report/code/launch.txt
Normal file
20
report/code/launch.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
void launch_program(StringArray *args) {
|
||||
pid_t child = 0;
|
||||
|
||||
child = fork();
|
||||
|
||||
if (child == 0) {
|
||||
if (execvp(args->array[0], args->array) == -1) {
|
||||
fprintf(stderr, "%s: command not found\n", args->array[0]);
|
||||
free_string_array(args);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else if (child < 0) {
|
||||
perror("fork");
|
||||
}
|
||||
else {
|
||||
int child_status;
|
||||
waitpid(child, &child_status, 0);
|
||||
}
|
||||
}
|
25
report/code/loop.txt
Normal file
25
report/code/loop.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
void loop() {
|
||||
while (1) {
|
||||
print_input_line();
|
||||
|
||||
char *line = get_console_input();
|
||||
|
||||
StringArray args;
|
||||
create_string_array(&args);
|
||||
|
||||
char *saveptr = NULL;
|
||||
char *token = strtok_r(line, " ", &saveptr);
|
||||
while (token) {
|
||||
insert_string_array(&args, token);
|
||||
token = strtok_r(NULL, " ", &saveptr);
|
||||
}
|
||||
|
||||
if (args.size == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_builtin(args.array[0])) {
|
||||
run_builtin(&args);
|
||||
}
|
||||
}
|
||||
}
|
44
report/code/redirection.txt
Normal file
44
report/code/redirection.txt
Normal file
@@ -0,0 +1,44 @@
|
||||
typedef struct {
|
||||
int fd;
|
||||
int fd_new;
|
||||
int fd_copy;
|
||||
char *filename;
|
||||
int flags;
|
||||
} Redirect;
|
||||
|
||||
Redirect in = {.fd = STDIN_FILENO, .fd_new = -1, .fd_copy = -1, .filename = NULL, .flags = O_RDONLY};
|
||||
Redirect out = {.fd = STDOUT_FILENO, .fd_new = -1, .fd_copy = -1, .filename = NULL, .flags = O_WRONLY | O_CREAT | O_TRUNC};
|
||||
Redirect err = {.fd = STDERR_FILENO, .fd_new = -1, .fd_copy = -1, .filename = NULL, .flags = O_WRONLY | O_CREAT | O_TRUNC};
|
||||
|
||||
void open_redirect(Redirect *redirect) {
|
||||
redirect->fd_copy = dup(redirect->fd);
|
||||
if (redirect->fd_copy == -1) {
|
||||
perror("dup");
|
||||
}
|
||||
else {
|
||||
redirect->fd_new = open(redirect->filename, redirect->flags, 0664);
|
||||
if (redirect->fd_new == -1) {
|
||||
fprintf(stderr, "open: Could not open file %s: \"%s\"\n", redirect->filename, strerror(errno));
|
||||
}
|
||||
else {
|
||||
if (close(redirect->fd) == -1) {
|
||||
perror("close");
|
||||
}
|
||||
if (dup(redirect->fd_new) == -1) {
|
||||
perror("dup");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void close_redirect(Redirect *redirect) {
|
||||
if (close(redirect->fd_new) == -1) {
|
||||
perror("close");
|
||||
}
|
||||
if (dup2(redirect->fd_copy, redirect->fd) == -1) {
|
||||
perror("dup2");
|
||||
}
|
||||
if (close(redirect->fd_copy) == -1) {
|
||||
perror("close");
|
||||
}
|
||||
}
|
6
report/sections/codigo.tex
Normal file
6
report/sections/codigo.tex
Normal file
@@ -0,0 +1,6 @@
|
||||
\section{Código}
|
||||
\input{sections/codigo/ciclo}
|
||||
\input{sections/codigo/builtins}
|
||||
\input{sections/codigo/permutar}
|
||||
\input{sections/codigo/redireccion}
|
||||
\input{sections/codigo/environ}
|
6
report/sections/codigo/builtins.tex
Normal file
6
report/sections/codigo/builtins.tex
Normal file
@@ -0,0 +1,6 @@
|
||||
\newpage
|
||||
\subsection{Builtins}
|
||||
Los builtins son comandos que son parte del shell, por lo tanto el sistema operativo no los proporciona. Un ejemplo es el comando\
|
||||
''exit''. Este comando no existe en el sistema operativo, por lo tanto el shell debe actuar cuando el usuario lo escribe en vez\
|
||||
de lanzar un proceso nuevo.
|
||||
\lstinputlisting{code/builtins.txt}
|
6
report/sections/codigo/ciclo.tex
Normal file
6
report/sections/codigo/ciclo.tex
Normal file
@@ -0,0 +1,6 @@
|
||||
\subsection{Ciclo principal}
|
||||
El ciclo principal controla todo la funcionamiento del shell. El ciclo debe correr infinitamente hasta que recibe un señal o un\
|
||||
comando de salir(exit). La primera cosa que tiene que hacer en el ciclo es mostrar un mensaje de entrada y esperar que el\
|
||||
usuario ingresa un comando. Luego separar la entrada en varios argumentos. Finalmente interpretar los argumentos y decidir que\
|
||||
hacer con ellos.
|
||||
\lstinputlisting{code/loop.txt}
|
8
report/sections/codigo/environ.tex
Normal file
8
report/sections/codigo/environ.tex
Normal file
@@ -0,0 +1,8 @@
|
||||
\newpage
|
||||
\subsection{Entorno}
|
||||
El entorno está controlado por un struct de array de strings de llaves y valores. Se inserta y busca adentro de estos array de llaves\
|
||||
para encontrar y usar el variable de entorno. En el shell el struct es usado como un variable global para que se puede accederlo\
|
||||
desde cualquier parte del código que se necesita los variables de entorno. Lo mas importante son 2 funciones, set\_array\_list y\
|
||||
get\_array\_list. Se usa set\_array\_list para insertar o sobre escribir un variable de entorno. Y el get\_array\_list retorno un\
|
||||
valor si se encuentre en el array list basado en la llava pasado a la función como parámetro.
|
||||
\lstinputlisting{code/environ.txt}
|
6
report/sections/codigo/permutar.tex
Normal file
6
report/sections/codigo/permutar.tex
Normal file
@@ -0,0 +1,6 @@
|
||||
\newpage
|
||||
\subsection{Permutar}
|
||||
Permutar es la parte responsable por correr un programa que está en el sistema operativo o en PATH. Para hacer eso\
|
||||
primer hacemos un fork donde el hijo permuta la operación y el padre espera que su hijo termina. Luego pasamos un nombre\
|
||||
de programa a permutar y sus argumentos al execvp.
|
||||
\lstinputlisting{code/launch.txt}
|
12
report/sections/codigo/redireccion.tex
Normal file
12
report/sections/codigo/redireccion.tex
Normal file
@@ -0,0 +1,12 @@
|
||||
\newpage
|
||||
\subsection{Redireccionamiento}
|
||||
Para redireccionar las entradas y salidas se usa 4 comandos principales, dup, dup2, open y close. El primer paso a tomar\
|
||||
es duplicar la entrada o salida(stdin, stdout o stderr) con dup. Eso es importante para restaurarlo después. Luego se abre el archivo\
|
||||
de salida o entrada usando open y los flags correspondiente a la operación que quiere\
|
||||
hacer(O\_RDONLY, O\_WRONLY, O\_CREATE, O\_APPEND o O\_TRUNC). Después, cerra stdin, stdout o stderr. Eso va a dejar su fd disponible para\
|
||||
usar. Finalmente hacer una duplicación con dup del fd de archivo de entrad o salida. Eso va a dejar el archivo usando el fd que
|
||||
cerramos anteriormente. Ahora todos las cosas mandados al stdin, stdout o stderr van a ser redirigidas al archivo. Para terminar\
|
||||
cerramos el archivo usado. Luego usamos dup2 para duplicar la copia original en su fd original. I finalmente cerramos la copia.\
|
||||
Para que funciona eso, debe abrir el redireccionamiento antes de llamar los builtins o permutar y cerrarlo después que termina\
|
||||
correr los builtins o el proceso hijo.
|
||||
\lstinputlisting{code/redirection.txt}
|
5
report/sections/conclusiones.tex
Normal file
5
report/sections/conclusiones.tex
Normal file
@@ -0,0 +1,5 @@
|
||||
\section{Conclusiones}
|
||||
Lo cosa mas importante que se puede aprender del proyecto es que el shell es un puente entre el usuario y el sistema operativo.\
|
||||
El shell es responsable para lanzar programas, interpretar comandos y en shells mas avanzados interpretar un lenguaje de\
|
||||
scripting para poder facilitar tareas o automatizarlas. Por lo tanto el shell es una parte integral para el sistema operativo\
|
||||
especialmente en sistemas como GNU/Linux o BSD.
|
38
report/sections/funcionamiento.tex
Normal file
38
report/sections/funcionamiento.tex
Normal file
@@ -0,0 +1,38 @@
|
||||
\section{Funcionamiento}
|
||||
El myshellin consiste de 3 partes importantes, los comandos "builtins", permutar y redireccionamiento.
|
||||
|
||||
\subsection{Builtins}
|
||||
Los builtins son comandos que son proporcionados por el shell en vez de un programa que provee el sistema operativo. Los comandos\
|
||||
que proporciona el myshellin son:
|
||||
\begin{itemize}
|
||||
\item help \newline \Quad mostrar una mensaje de ayuda de como usar el shell.
|
||||
\item environ \newline \Quad imprimir todos los variables del entorno.
|
||||
\item set \newline \Quad crear o sobre escribir un variable de entorno.
|
||||
\item echo \newline \Quad imprimir un comentario o variable.
|
||||
\item cd \newline \Quad cambiar el directorio donde está trabajando el shell.
|
||||
\item exit \newline \Quad salir del shell.
|
||||
\end{itemize}
|
||||
|
||||
Cuando el comando que ingreso el usuario no es un builtin el siguiente paso es tratar de permutar un software que proporciona el\
|
||||
sistema operativo.
|
||||
|
||||
\subsection{Permutar}
|
||||
Para permutar un programa de sistema, el proceso de myshellin hace una llamada al fork para crear un proceso hijo. Luego el\
|
||||
proceso hijo intenta permutar con el comando execvp. Lo que hace eso es reemplazar el proceso hijo con el proceso del programa\
|
||||
que proporciona el sistema operativo como ls, rm, df, du, etc. Mientras que corre el programa el proceso padre espera que\
|
||||
termina el proceso hijo antes que puede seguir pidiendo que el usuario ingresa otros comandos.
|
||||
|
||||
\newpage
|
||||
\subsection{Redireccionamiento}
|
||||
Redireccionamiento es el proceso de redirigir los contenidos de una entrada o salida al stdin, stdout o stderr. Por ejemplo\
|
||||
se puede redirigir todo el contenidos que se debe imprimir en stdout a un archivo usando el símbolo ``>`` seguido por un nombre\
|
||||
de archivo. En el shell existen los siguientes tipos de redireccionamiento:
|
||||
\begin{itemize}
|
||||
\item > \newline \Quad redirigir el stdout a un archivo y borrar el contenido anterior si existe el archivo.
|
||||
\item >\null> \newline \Quad redirigir el stdout a un archivo y agregue el el contenido nuevo al final del archivo si existe.
|
||||
\item 1> \newline \Quad redirigir el stdout a un archivo y borrar el contenido anterior si existe el archivo.
|
||||
\item 1>\null> \newline \Quad redirigir el stdout a un archivo y agregue el el contenido nuevo al final del archivo si existe.
|
||||
\item 2> \newline \Quad redirigir el stderr a un archivo y borrar el contenido anterior si existe el archivo.
|
||||
\item 2>\null> \newline \Quad redirigir el stderr a un archivo y agregue el el contenido nuevo al final del archivo si existe.
|
||||
\item < \newline \Quad redirigir el contenido de un archivo al stdin.
|
||||
\end{itemize}
|
3
report/sections/introduccion.tex
Normal file
3
report/sections/introduccion.tex
Normal file
@@ -0,0 +1,3 @@
|
||||
\section{Introducción}
|
||||
El propósito del proyecto semestral es crear un shell básico para aprender los básicos de que hace un shell en un sistema\
|
||||
operativo. Hay varios partes que son importante como la creación de procesos, redireccionamiento y el entorno.
|
BIN
report/ubblogo.png
Normal file
BIN
report/ubblogo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 185 KiB |
Reference in New Issue
Block a user