Lab2-Process

Lab2-Process - Lab 2 Working with Processes in Linux/Unix...

Info icon This preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Lab 2 Working with Processes in Linux/Unix
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Before You Start… Login to Linux Boot the PC, and select the option: SLIM/SWIM Choose 5 Ubuntu 10.04 Login the system using CS account info Download lab2.tgz from course webpage to Desktop Then, in a terminal cd ~/Desktop tar xzvf lab2.tgz cd lab2 make When you see Try these command(s) in your terminal TRY!
Image of page 2
ps - Show Processes information All processes in Linux/UNIX can be shown by using ps Usage: ps [option] When executed without any options, only processes that are associated with the current terminal are shown. Use man-page to learn how to use Some Useful options -e: show all processes -f: show in full format ps ps -ef ps -ef --headers | less TRY!
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
kill - Terminate a process Process can be terminated explicitly by using the command kill -9 <process id> means to send a SIGKILL signal to a process, and that process will be terminated when it received it End all processes of that program name killall -9 <program name> Open 2 terminals, in one terminal Execute cd ~/Desktop/lab2 Execute ./dummy& for 3 times In another terminal, to find out the PID of one of the processes Execute ps -ef | grep dummy To kill that process with PID 1234 Execute kill -9 1234 To show the current situation Execute ps ef | grep dummy To end all processes with program name "dummy“ Execute killall -9 dummy To show processes with program name "dummy“ Execute ps -ef | grep dummy TRY! Just an example
Image of page 4
fork Create new process When a process calls fork() a new process (child process) is created (by cloning the initiating process) the initiating process becomes the parent process. The child process shares the same program code as the parent process and have the same contents in the variables However, they have different process IDs Actually, they are 2 different processes Both processes continue the execution at the point after fork() After that, modifications of variables won’t affect the value of the other processes As both parent and child process execute the same program code, the return value of fork() is used to determine their identities (parent or child) determine which parts of the code are executed
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
fork Create new process For parent process, return value of fork() with - 1 means error (can’t create new process) Otherwise, a +ve value is returned. The value is the process ID of the
Image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern