Processes Lab | Unix Linux Forums | Homework & Coursework Questions

  Go Back    


Homework & Coursework Questions Students must use and complete the template provided. If you don't, your post may be deleted! Special homework rules apply here.

Processes Lab

Homework & Coursework Questions


Tags
homework, unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-09-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Processes Lab

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:

Here are my directions. I am pretty sure I am doing this right, but I just want someone more experienced to look over my work. Thank you.

There are two parts. It seems long but it's not. For both I need to record my inputs into a script file :

Part 1:

1) Start the command "sleep 6000" in the background
2) Use ps to determine its status
3) Redirect the ps command to a file
4) Kill the sleep process
5) Run ps to verify the process is dead.

Part 2: (Working with multiple processes)

1) Start up "sleep 6000" in the background
2) Start up "sleep 3000" with nohup in the background
3) Bring "sleep 6000" to the foreground
4) Suspend "sleep 6000"
5) Use ps or jobs to verify the state of all processes
6) Send a copy of ps to a file and print it
7) Kill both processes

2. Relevant commands, code, scripts, algorithms:

The relevant commands would be those located under processes, since that is the section we are working on now.


3. The attempts at a solution (include all code and scripts):

First I do "touch lab5file" to create a file, then I do "script lab5" to record my inputs (My teacher wants one script file for both parts - he does not want the output, just commands)

Part 1:

1. sleep 6000 &
2 + 3. ps > /var/home/stud3/jgeiger/lab5file
4. kill -9 <PID number here>
5. ps

Part 2:

1. sleep 6000 &
2. nohup sleep 3000 &
3. fg %<job number for sleep 6000 here>
4. ctrl + z
5 + 6. ps > /var/home/stud3/jgeiger/lab5file
7. kill -9 <PID number for sleep 6000>
8. kill -9 <PID number for sleep 3000>

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):

Brookdale Community College - Lincroft, New Jersey - United States - Dr. Rick Bournique- COMP 145

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by Jagst3r21; 03-09-2013 at 10:26 PM.. Reason: course link
Sponsored Links
    #2  
Old 03-10-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 29 July 2014, 5:18 PM EDT
Location: Aachen, Germany
Posts: 3,923
Thanks: 62
Thanked 931 Times in 883 Posts
Both your solutions will do the job. You didn't print as requested in 2.6, and you didn't mention the jobs' statuses. What status would you expect them in?
Use kill -9 only as a last resort for otherwise unaccessible processes. Usually, the default 15 (TERM) is sufficient. And, you can list several processs to kill in one command.
Sponsored Links
    #3  
Old 03-10-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 29 July 2014, 5:34 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,130
Thanks: 44
Thanked 772 Times in 608 Posts
Your solutions are correct to the point that they are working. The following is just a bit of additional information you might find useful. I noticed, that you have no solution for question 2.7, probably an oversight?

RudiC is correct: "kill -9" means the OS actively terminates the process. "kill -15" on the other hand tells the process to shut down immediately. In your case this will not make that much difference, but if a process has open temporary files or logs to be written, or any other allocated resources, "kill -15" will allow it to neatly close all these before exiting while "kill -9" will leave all these open and hanging in limbo.

I don't know which shell you use, but most probably it is either bash or ksh. In both cases you can make use of the job control of this shell: issue "jobs" to see a list of jobs in the background and use "kill %<number>" instead of "kill <PID>" to address the process.

The "kill" command can take a list of PIDs to process. Instead of


Code:
kill -9 <PID1>
kill -9 <PID2>
kill -9 <PID3>
...

it is posssible to write


Code:
kill -9 <PID1> <PID2> <PID3> ...

I hope this helps.

bakunin
The Following User Says Thank You to bakunin For This Useful Post:
Jagst3r21 (03-10-2013)
    #4  
Old 03-10-2013
Jagst3r21 Jagst3r21 is offline
Registered User
 
Join Date: Mar 2013
Last Activity: 6 May 2013, 12:19 AM EDT
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Thanks for the responses and tips. How come for 2.3 I cannot enter another command? After I do
Code:
fg %<job number for sleep 6000 here>

I do not get the dollar sign back to proceed and do
Code:
ctrl + z

for
Code:
nohup sleep 3000 &

. I realize now that I am not sure how to make the ctrl + z targets the nohup sleep 3000 & command either.

Thanks again in advance,

James
Sponsored Links
    #5  
Old 03-10-2013
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 29 July 2014, 5:34 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,130
Thanks: 44
Thanked 772 Times in 608 Posts
Quote:
Originally Posted by Jagst3r21 View Post
How come for 2.3 I cannot enter another command? After I do
Code:
fg %<job number for sleep 6000 here>

I do not get the dollar sign back to proceed and do
Code:
ctrl + z

for
Code:
nohup sleep 3000 &

.
I'd say works as designed. ;-)) "fg" is the command to get to the FOREGROUND a process which was previously put into the BACKGROUND (or has been suspended). As long as a process is running in the foreground you get no prompt (it is often a dollar sign, but it doesn't have to), because the prompt display is the shells way of saying "there is no process in foreground so i am ready for input".

Quote:
Originally Posted by Jagst3r21 View Post
I realize now that I am not sure how to make the ctrl + z targets the nohup sleep 3000 & command either.
Of all the processes running from your shell there can be none, one or several in the background and none or one (not several!) in the foreground. This answers the question: "CTRL-Z" or other job-control key sequences ("CTRL-C", for instance) only affect the process running in the foreground.

I hope this helps.

bakunin
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lab ^ herb bertz Homework & Coursework Questions 13 03-10-2013 11:55 PM
help me with lab im new to bash.... elginmulizwa Shell Programming and Scripting 1 10-04-2011 12:07 AM
Help completing lab. ink Homework & Coursework Questions 4 09-29-2010 10:54 AM
cant complete lab ??? ink Shell Programming and Scripting 1 09-28-2010 05:52 PM
Shell Script Lab rktompsett Programming 1 04-27-2010 10:16 AM



All times are GMT -4. The time now is 06:54 PM.