Operating System experiments are difficult-system calls

Source: Internet
Author: User
It is difficult to test the operating system-System Call-general Linux technology-Linux programming and kernel information. The following is a detailed description. Author: awkward child

Lab content
The basic content of this experiment is: Add two system calls on Linux 0.11, and write two simple applications to test the system calls. The experiment process is divided into two steps.

The first step is to add a system call whoami () on Linux 0.11. The prototype is as follows:

Int whoami (void );

The function called by the system is to print the user name (for example, Li Zhijun) to the screen. The User Name string is written in the kernel source code. Then write a test program whoami in Linux 0.11, which calls whoami () to get its name and print the string "I am XXX" on the standard output device (usually on the screen. ". The returned value is any non-negative number.

Step 2 add another system call iam () on Linux 0.11. Its interface is:

Int iam (const char * name );

The completed function is to copy the content of the string parameter name passed in the user program to the core State data segment. The length of name must not exceed 20 characters. Assume that there is a global variable char myname [21] in the core State data segment, and iam copies the user State data name to the core State data myname. The returned value is the number of copied characters. If the number of characters in name exceeds the storage capacity of myname, "-EINVAL" is returned ".

Then modify the above whoami (). The new prototype is:

Int whoami (char * name, unsigned int size );

Instead of outputting anything to the screen, it copies the myname to the name and ensures that the name is not accessed across borders (the size of the name is determined by the size ). The returned value is the number of copied characters. If the size is smaller than the required space, "-EINVAL" is returned ".

Then implement a test program iam. The final requirement is:

$ Iam lizhijun
$ Whoami
I am lizhijun

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.