Linux project no 1

524 views
436 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
524
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linux project no 1

  1. 1. Linux project no 1 address: http://www.csie.ncu.edu.tw/~hsufh/COURSES/FALL2008/linux_project1.html now is 20081208 Mon: I try again to do implementing system call http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ and rebuild kernel http://www.cromwell-intl.com/unix/linux-kernel.html I append today's date as the label, ie. 20081208 folder is in /usr/src/linux*-20081208 name of the new build is also wit *-20081208 I already expand my vmware disk vmdk with this command: http://blogs.developerfusion.co.uk/blogs/thushan/archive/2007/04/16/2629.aspx All files modified are backed up using this extension: *.nur test file is in ~/system-call-examples/20081208/ ------- Old: --------------- trying this: http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ -- twice & not successfull: rebuild kernel & install kernel give no error compile test code (testmycall.c) gives the following errors: Error code for the second trial: --------------------------------- In file included from testmycall.c:7: testmycall.h:9: error: expected declaration specifiers or ‘...’ before ‘mycall’ testmycall.h:9: error: expected declaration specifiers or ‘...’ before ‘i’ testmycall.c: In function ‘_syscall1’: testmycall.c:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
  2. 2. testmycall.h:9: error: parameter name omitted testmycall.h:9: error: parameter name omitted testmycall.c:15: error: expected ‘{’ at end of input --------------------------------- command to capture out and error: ./cmd 1>out.txt 2>err.txt I will try another steps from: http://lwyy.eboler.com/2006/12/3/ How to build a kernel? http://www.howtoforge.com/kernel_compilation_fedora http://www.mjmwired.net/resources/mjm-kernel-fc4.html Already done with Dung and successful: http://www.cromwell-intl.com/unix/linux-kernel.html Need to do: Modify kernel Compile kernel Restart using new kernel Add a new system call: http://www.ibm.com/developerworks/library/l-system-calls/index.html simplified system call with interrupt:
  3. 3. ========= IMPORTANT ============= Seems more practical resource is: (this is step by step instruction to create a new system call!) http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/ WORTH READING [SHOULD BE READ FIRST!] http://www.cmpe.boun.edu.tr/courses/cmpe322/fall2008/Tutorials/Kernel%20Compile%20and %20SysCall%20Add%20(Ubuntu%208.04).pdf (Similar to above, but for UBUNTU!) Detailed steps begin on page 4/6. ========= IMPORTANT ============= http://www.linuxjournal.com/article/3326 --> THIS IS like previous resource, and there IS steps to compile kernel! [WORTH READING] But it is obsolete! December 1st, 1999 You will read that we should use a floppy! Obsolete: http://www.csee.umbc.edu/courses/undergraduate/CMSC421/fall02/burt/projects/howt o_add_systemcall.html http://www.csee.umbc.edu/courses/undergraduate/CMSC421/fall02/burt/projects/howto_build_ke rnel.html Similar project with detailed instructions: http://www.cs.duke.edu/courses/spring05/cps210/Lab1.html
  4. 4. http://syn.cs.pdx.edu/~jsnow/ta/timer.html (Not checked) Other links to check include: http://lwn.net/Articles/281965/ NOT WORTH READING Comment: .... this is new : May 14, 2008! but let me read first. And unfortunately, this is not a basic article to read! Part 1 First we edit the following program (with vim): #include <stdio.h> main() { while(1) ; } save the code as orchid.c then we compile it with gcc gcc orchit c -o orchid then we run it in the background: ./orchid & (to create another background process, just repeat that command. We need to make 20 background processes.) to view the process ID we use command ps After we found PID, we can see the memory location with this command (http://www.cyberciti.biz/tips/howto-find-memory-used-by-program.html ) $ pmap PID $ pmap 3724 And now we will create a C program to find the address of each task_struct data generated by each our orchid program. Resources helping us in doing this include:
  5. 5. http://www.informit.com/articles/article.aspx?p=370047 http://linuxgazette.net/133/saha.html but how to print each address pointing to task_struct data. This may help us: http://stackoverflow.com/questions/197757/printing-pointers-in-c We now hope those above will solve our fist part of project 1. We have unsolved problem when compiling this code: We try to compile this simple C code (Cobaba.c): #include </usr/include/linux/kernel.h> #include </usr/include/linux/sched.h> #include </usr/include/sepol/module.h> int main() { struct task_struct *task; for_each_process (task) { printk("%s[%d]n", task->comm, task->pid); //printf("hello"); } return 0; } We found compile errors like this: Cobaba.c: In function ‘main’: Cobaba.c:9: error: expected ‘;’ before ‘{’ token What's wrong with our code? But it seems that we get the answer here:
  6. 6. http://www.linuxquestions.org/linux/articles/Technical/Linux_Kernel_Thread Part 2 Now we will go to explore and understand second part of project 1. (although part 1 have not been solved yet) First question of part 2: After the above experiment, terminate the execution of the above 20 processes, and then execute orchid in the background. Then list (1) the PID of the group leader of the process that executes the above orchid and (2) the PID of the group leader of the shell process that creates the process which executes the above orchid. Answer: To terminate 20 process from part 1, we use kill command. $ kill PID How do we know the PID of the process(es) that we want to kill? Use ps command as above. After we kill all orchid processes, we start one orchid process in the background, then list the PID of the group leader of the process. What does group leader mean? Does it mean parent of the process? To list PID

×