Lab2-Process

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

Info iconThis 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
Background image of page 1

Info iconThis 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!
Background 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!
Background image of page 3

Info iconThis 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
Background 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
Background image of page 5

Info iconThis 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
Background 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 ]}

Page1 / 23

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

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online