Question

1. Download the sources of the Linux kernel (of the version matching the kernel version of your current installation) from http://kernel.org into some directory in your home directory. Unzip and untar it. Change into the root directory of the kernel source tree. Traverse through the directories. Find out where the getpid system call is located in the kernel sources. Write down the name of that file. Describe how you found that file. Examine that source file. What is the name of the corresponding system call routine? Write down the implementation of the getpid system all. What is the number of the getpid system call. Describe how you found that number.

2. Learn the architectures that Linux supports from the arch subdirectory of the Linux kernel source tree. Write them down.

3. Write a small C program in the Linux environment. The program will just compute the average of the integers that are found in a given input file. The first line in the file should contain the number of integers, and the remaining lines should contain the actual integers, one integer per line. The output will be written to the screen. Compile the program with gcc. Use the -g and -w options for the compiler. Run the program. Provide the listing of the source code of the program.

4. Exercise with the strace utility. Print out a sample output using one of the basic Linux commands such as ls, cp, ps. Also write down the strace output for the executable that you built in the previous step.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

3
mean-int.c:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[]){
    FILE * fp;
    int nLines, line, number, sum= 0;
    double mean;

    if (argc!= 2){
            fprintf(stderr, "error: filename\n");
            return 1;
    }

    fp = fopen(argv[1], "r");
    if (fp == NULL){
            fprintf(stderr,"error: file\n");
            return 2;
    }

    fscanf(fp, "%d", &nLines);

    for(line= 1; line<= nLines; line++){
       fscanf(fp, "%d", &number);
       sum+= number;
    }

    mean = sum/ nLines;
    printf("%.2f\n", mean);

    fclose(fp);
    return 0;
}...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Shell Scripts & Programming Language C
Homework Solution
$30.00
Linux
Shell Scripts
Computer Science
Programming Language C
Lowercase
Uppercase
Backup Directory
Algorithms
File Management
Printing Messages
TCSH
Linux & C++ Problems
Homework Solution
$30.00
Computer Science
Linux
C++
Functions
Statements
Variables
Loops
Conditions
File Management
Commands
Codes
Child Processes
Command Line
Parent Processes
Executable Program
Buffers
Forks
Operators
Get help from a qualified tutor
Live Chats