Giter Club home page Giter Club logo

linux_system_call's Introduction

Linux_System_call

Sneha Sinha - 2016098, Ritu Kumari - 2016078

System Call for Linux written in C, compiling linux source code

Part 1: Compiling the source code

The linux 3.13.0 source code is downloaded and it's extracted.

  • cd to that directory
  • do 'cp /boot/config-$(uname -r) .config' to copy the kernel's .config file then followed by 'make menuconfig'
  • use 'sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4'.The kernel and modules are compiled.
  • do 'update-initramfs -c -k 3.13.0' to update the kernel.

Part 2: Writing a System Call

  • In the linux-3.13.0 dir, make a new dir and add the system call files there.
    • Make a new file sh_task_info.c - write_to_file function takes file* and char * as arguments and uses write() to write data in it. - In sys_sh_task_info(),a task_struct pointer task and struct file pointer file are created. For each task, it's
      attributes are printed on the console and simultaneously written to the file.
    • A header file for it, sh_task_info.h
    • A Makefile for compiling the above.
  • This new directory has to be added to the Linux-3.13.0's Makefile by changing the line 'core -y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/' to 'core -y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ newdir/'.
  • The pid for the new system call has to be added,in the arch/x86/syscalls/syscall_64.tbl. We added it at 318.
  • Then, the function was included in the syscalls.h in include/
  • It was recompiled again with the three parallel commands by 'sudo make -j 4 && sudo make modules_install -j 4 && sudo make install -j 4'.
  • The system is restarted.

Part 3: Testing it with sample code

  • The file taskinfo.c is the sample test code, compares the process IDs by using syscall. If the input process ID and the updated pid 318 match, and there is no error in the given pid and the filename sh_task_info() is executed correctly.
  • It should be run with 'gcc taskinfo.c -o test'
  • The executable is run with './test 1 testfile.txt'
  • If it executed successfully, we can check the log via 'dmesg'. The attributes corresponding to pid==1 are printed on the console.

  • The process, it's process ID, process state, RT_priority, static priority and normal priority are printed.
  • Alternatively, we can check the log with 'cat testfile.txt'.

Part 4: Errors Handled

    1. If the user doesn't enters an invalid pid such as a char or float
    1. If the user enters pid <=0 or greater than 32768, the function returns the errno 22 EINVAL invalid argument.
    1. If the sys_open() for creating a file if it doesn't exist, with write access returns an int less than 0, the function returns the errno 21 EISDIR is a directory.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.