Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 92 additions & 39 deletions ANSWERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,128 +19,181 @@ Please use [markdown](https://help.github.com/articles/markdown-basics) formatin

Make another directory inside the `unixstuff` directory called `backups`

**Answer:** *YOUR ANSWER HERE*
**Answer:** *`cd unixstuff`
`mkdir backups`*

###Exercise 1b

Use the commands `cd`, `ls` and `pwd` to explore the file system.

(Remember, if you get lost, type `cd` by itself to return to your home-directory)

**Answer:** *YOUR ANSWER HERE*
**Answer:** *` ls`
`cd ..`
`ls`
`cd unixstuff`
`pwd`*

###Exercise 2a

Create a backup of your `science.txt` file by copying it to a file called `science.bak`

**Answer:** *YOUR ANSWER HERE*
**Answer:** *` cp science.txt science.bak`*

###Exercise 2b

Create a directory called `tempstuff` using `mkdir`, then remove it using the `rmdir` command.

**Answer:** *YOUR ANSWER HERE*
**Answer:** *`mkdir tempstuff`
`rmdir tempstuff`*

###Exercise 3a

Using the above method, create another file called `list2` containing the following fruit: orange, plum, mango, grapefruit. Read the contents of `list2`.

**Answer:** *YOUR ANSWER HERE*
**Answer:** *`cat >list2`
`orange`
`plum`
`mango`
`grapefruit`
`ctrl+D`
`cat list2*`

###Exercise 3b

Using pipes, display all lines of `list1` and `list2` containing the letter 'p', and sort the result.

**Answer:** *YOUR ANSWER HERE*
**Answer:** *`cat list1 list2 | grep p | sort `*

###Exercise 5a

Try changing access permissions on the file `science.txt` and on the directory `backups`.

Use `ls -l` to check that the permissions have changed.

**Answer:** *YOUR ANSWER HERE*
**Answer:** *`chmod a+rwd science.txt`
`chmod u+777 backups `*

##Shell questions

1. What option with the command `rm` is required to remove a directory?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`rmdir`*
1. What is the command used to display the manual pages for any command?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`man command`*
1. What command will show the first 5 lines of an input file?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`head -5`*
1. What command can be used to rename a file?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`mv`*
1. What option can we given to `ls` to show the hidden files?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`ls -a`*
1. What will the command `cat -n file` do?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** * tell if file is a directory or a file*
1. What will the command `echo -n hello` do?
- **Answer:** *YOUR ANSWER HERE*
1. What command will display s list of the users who currently logged in in the system?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *write hello on the next line*
i. What command will display s list of the users who currently logged in in the system?
- **Answer:** *`who`*
1. How do you change password on your account?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`passwd`*
1. How can you list a file in reverse order?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`ls -reverse`*
1. What does the `less` command do?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *show one page at the time*
1. With `less` how do you navigate?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *press enter when you finished the page and q for exiting*
1. What command will display the running processes of the current user?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`jobs`*
1. What command can be used to find the process(es) consuming the most CPU?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`ps`*

##vi questions
1. How do we save a file in `vi` and continue working?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** * go on mode command then type :w and enter*
1. What command/key is used to start entering text?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *the key i*
1. What are the different modes the editor can be in?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *insert and command*
1. What command can be used to place the cursor at the beginning of line 4?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *#4*
1. What will `dd` command do (in command-mode)?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *delete the whole line the cursor is at*
1. How do you undo the most recent changes?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *on command press u*
1. How do you move back one word?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *b*

##The C Language and Make tool Questions

1. How do you use `gcc` to only produce the `.o` file? What is the difference between generating only the `.o` file, and building the `hello` executable done in the previous compilation above?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *when you are compiling just use gcc -c fichier.c. The difference is that with .o you can edit links with other files whereas with the executable file you can not*
1. Give the command for compiling with `debug` enabled instead of normal compilation for the two examples shown in Listing 2 and Listing 3. Explain how to turn debugging on/off for the two cases.
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** * `gcc -DDEBUG`for listing2 and change the number for Listing3*
1. Give a brief pros and cons discussion for the two methods to add debug code shown in Listing 2 and Listing 3.
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *in listing2 the debugging will take place only if we use the command -g when compiling. If we don t the code between the ifdef and ifnotdef wont be used or executed. It can be useful when a little part does not work but does not affect the general system. On top of that it won't use any place if it is not called. In Listing3 the debugging will always appeared so it can be frustrating when you have to compile a lot in order to see if the rest of the code is working. *
1. Provide the command for generating the *map* file. Which of the `gcc` tools is responsible for producing a *map* file?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`gcc -W1, -MAP`*
1. What is the content of each of the sections in a *map* file. Explain briefly.
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *Text contains the code. Data the variable initialized, bss those unintialized and rodata the const variables *
1. Rewrite `hello.c` to produce entries in the *map* file for `.data`, `.bss`, and `.rodata`. Hint: This can be done by adding one variable for each type to the file.
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *

#include<stdio.h>
int main (void)
{
int i;
string d="Hello world\n";
const int j;
return 0;
}

*
1. Add the following function to `hello.c`: `double multiply(double x1, double x2)`, which returns `x1*x2`. Use `gcc` to generate an assembly code listing for the program, and examine the assembly code. What assembly instructions are used to do this? Repeat this task, but now replace `double` with `float`. Explain!
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *mulsd is used to multiply to double. When multiplying two floats the assembly code is mulss. It is because double and float do not use the same amount of space and are not store the same.*
1. How does `make` know if a file must be recompiled?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** * If the header of the file has changed then make recompile the file.*
1. Provide a `make` command to use a file named `mymakefile` instead of the default `makefile`.
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *`make -f mymakefile`*
1. How do you implement an *include guard*, and why is it needed?
- **Answer:** *YOUR ANSWER HERE*
- **Answer:** *an include guard is used to prevent the double inclusion of an header. It prevents the compiler to bug because one header will be present two times.*

##Library Task

Insert your code between the brackets `{}`:

void main( int argc, char *argv[] )
{
int nb;
double result;
printf("Please enter the desired size of the table\n");
scanf("%d", &nb);
int[nb] table;
for(int i=0; i<nb-1;i++){
table[i]=random(101);
}
result=tab_sort_sum(table, nb);
printf("The sum is : %d\n",&result);
printf("The table is now ");
for(int i=0; i<nb-1;i++)
printf("\n %", &table[i]);
}

double tab_sort_sum( double *tab, int tab_size )
{
for(i=0;i<tab_size;i++)
{
for(j=i+1;j<tab_size;j++)
{
if(table[i]>table[j])
{
temp=table[i];
table[i]=table[j];
table[j]=temp;
}
}
}
double sum=0;
for(int i=0; i<tab_size;i++)
sum=sum+tab[i];
return sum;
}


13 changes: 13 additions & 0 deletions HelloWord.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stdio.h>
double multiply(double x1, double x2)
{
return x1*x2;
}

int main(void)
{

printf("Hello word !\n");
return 0;

}