Presentation is loading. Please wait.

Presentation is loading. Please wait.

U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, 2006 10/22/2009 rwjBROOKDALE.

Similar presentations


Presentation on theme: "U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, 2006 10/22/2009 rwjBROOKDALE."— Presentation transcript:

1 U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, 2006 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE1

2 2 U NIX O PERATING S YSTEM T HE UNIX PROCESS STRUCTURE P ROCESS I NITIALIZATION S EQUENCE P ROCESS C ONTROL C OMMANDS R UNNING S HELL S CRIPTS IN B ACKGROUND P ROCESS S IGNALING AND E XIT S TRUCTURE E XECUTE &T ERMINATE P ROCESSES S CHEDULE A P ROCESS TO R UN A UTOMATICALLY 10/22/2009 rwj

3 BROOKDALE COMMUNITY COLLEGE3 T HE P ROCESS A N INSTANCE OF A PROGRAM IN EXECUTION. I DENTIFIED BY A UNIQUE PID (P ROCESS - ID ). C REATED BY ANOTHER PROCESS AS ITS CHILD O NE PROCESS CAN BE PARENT OF MULTIPLE CHILDREN C AN BE KILLED OR STOPPED BY SENDING IT A SIGNAL 10/22/2009 rwj

4 T HE P ROCESS C YCLE P ARENT FORKS A CHILD BY 1 ST REPLICATING ITS OWN PROCESS IMAGE AND LOGGING THE CHILD IN THE PROCESS TABLE. C HILD EXECUTES ( OVERWRITES ) THIS IMAGE WITH THAT OF ANOTHER PROGRAM. W HILE CHILD IS RUNNING, PARENT MAY  W AIT FOR CHILD TO COMPLETE EXECUTION (I F A CHILD EXECUTING IN FOREGROUND )  C ONTINUE WITH ITS OTHER TASKS (I F A CHILD EXECUTING IN FOREGROUND ) P ROCESS TERMINATES AND PARENT PICKS UP EXIT STATUS OF CHILD.  Until Parent picks up exit status of child, process called a ZOMBIE, because process not removed K ERNEL REMOVES ENTRY FOR DEAD CHILD FROM PROCESS TABLE. 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE4

5 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE5 T HE P ROCESS C YCLE (contd) I F P ARENT PROCESS DIES BEFORE A CHILD PROCESS  C HILD PROCESS CALLED AN ORPHAN  P ROCESS init BECOMES PARENT OF CHILD, AS IT IS FOR MOST DAEMONS  O RPHAN PROCESSES CONTINUE TO OPERATE UNTIL ITS KILLED OR ENDS NORMALLY.

6 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE6 M ORE ON THE P ROCESS B UILT IN S HELL COMMANDS DO NOT FORK SEPARATE A PROCESS  F OR EXAMPLE : cd or pwd S HELL SCRIPTS USE SUB - SHELLS TO RUN COMMANDS IN SCRIPT SIGNALS: U SED BY K ERNEL TO COMMUNICATE WITH A PROCESS  kill -s, OR  GENERATED THROUGH YOUR keyboard

7 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE7 P ROCESS A TTRIBUTES I NHERITED BY C HILD Real User ID (UID) and Group (GID) Effective UID and GID Current directory File descriptors umask value Environment variables

8 PID  Process ID – referred to as “pid”  When born, logged in Process Table with unique number  Used to track and kill a process  Stored in variable $$  To see or show value of $$ use echo $$ PPID  Parent PID, referred to as “p-pid”  Can be used to kill a child process but only be used if 1 child spawned $ ps PID TT STAT TIME COMMAND 64199 p3 S 0:00.00 -ksh (ksh) 64218 p3 R+ 0:00.00 ps $ P ROCESS A TTRIBUTES N OT I NHERITED BY C HILD 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE8

9 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE9 P ROCESS C ONTROL C OMMANDS ps ( PROGRAM STATUS ) kill ( TERMINATE PROCESS )

10 D ISPLAY ENVIRONMENT  S PECIFIES A LIST OF DIRECTORIES TO SEARCH. $ ps –e PID TT STAT TIME COMMAND 64199 p3 S 0:00.00 -ksh (ksh) 64304 p3 R+ 0:00.00 ps –e P ROGRAM S TATUS ( ps ) BROOKDALE COMMUNITY COLLEGE1010/22/2009 rwj

11 D ISPLAY COMMAND - LINE AND ENVIRONMENT INFO ABOUT SWAPPED OUT PROCESSES. UID OF USE MUST BE 0. $ ps –f PID TT STAT TIME COMMAND 64199 p3 S 0:00.00 -ksh (ksh) 64305 p3 R+ 0:00.00 ps –f 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE11 P ROGRAM S TATUS ( ps ) (contd)

12 D ISPLAY DETAILED PROCESS LISTING $ ps –l UID PID PPID CPU PRI NI VSZ RSS MWCHAN STAT TT TIME COMMAND 83641 75606 75605 0 20 0 1996 540 pause S p3 0:00.00 -ksh (ksh) 83641 75610 75606 0 96 0 5776 992 - R+ p3 0:00.00 ps –l 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE12 P ROGRAM S TATUS ( ps ) (contd)

13 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE13 R UNNING JOBS IN THE B ACKGROUND A PPEND & ( AMPERSAND ) TO THE END OF A SHELL OR COMMAND  S HELL OPERATOR TO RUN IN BACKGROUND  F REES KEYBOARD AND SCREEN FOR USE. $ sort empl.lst > junk2 &

14 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE14 R UNNING JOBS IN THE B ACKGROUND (contd) P REPEND nohup ( NO HANG UP ) IN FRONT OF A SHELL OR COMMAND  S HELL OPERATOR TO NOT TERMINATE THE COMMAND RUNNING IN BACKGROUND EVEN IF THE SESSION ENDS $ nohup sort empl.lst > junk2 &  U NIKE &, USE nohup WITH EACH COMMAND IN A PIPELINE, E. G. $ nohup grep directory | nohup sort > empl_directors_sorted&

15 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE15 P ROCESS S IGNALING AND E XIT S TRUCTURE J OB CONTROL USES AS IT RELATES TO PGID  M OVE JOBS BETWEEN FOREGROUND AND BACKGROUND  C OMMANDS fg bg suspend ( OUTPUT TO TERMINAL ) jobs ( LISTS CURRENTLY ACTIVE JOBS ) kill ( TERMINATES JOBS ) ctl-z ( SUSPENDS CURRENT FOREGROUND JOB )

16 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE16 E XECUTE & T ERMINATE P ROCESSES J OB CONTROL COMMANDS  S TART A COMMAND IN THE BACKGROUND $ find / -name a.out –print > files_to_remove 2>dev/null & [1] 1287 $ ls -lR / > system_list 2>dev/null & [2] 1288 $ du -s /usrs1/* > disk_usage & [3] 1289 S TOP OUTPUT TO THE TERMINAL + SUSPEND JOB  S USPENDS JOB WHEN TRIES TO WRITE TO TERMINAL $ stty tostop

17 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE17 E XECUTE & T ERMINATE P ROCESSES (contd) U SE OF JOB CONTROL FUNCTIONS  U SING JOB NUMBER MOVE TO FOREGROUND $ fg %1  S USPENDS ONLY A FOREGROUND JOB $ [ ctl-z ]  U SING JOB NUMBER RETURN JOB 1 TO BACKGROUND $ bg %1  W HEN JOB ENDS NORMALLY GET $ [2]- Exit 1 ls -lR / > system_list 2>dev/null  W HEN JOB NEEDS TO BE KILLED MANUALLY USE $ kill %2 [1] + Terminated ls -lR / > system_list 2>dev/null

18 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE18 kill or  Pid SPECIFIES THE PROCESS THAT THE OS IS TO KILL  T HE RESULT IS NOT REVERSIBLE. $ kill 154339 $ kill %1 T ERMINATE P ROCESSES

19 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE19 D AEMON IN UNIX S CRIPTS THAT LACK TERMINAL CONTROL $ lpsched $ mail, mailx, cron ps –e SHOWS cron DAEMON RUNNING. P ROGRAMS INVOKED BY LAUNCHING A SHELL OR SUB - SHELL  S HELL S CRIPTS  S UB - SHELL READS & EXECUTES EACH STATEMENT IN SCRIPT

20 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE20 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY cron vs crontab  cron K ERNEL STARTED DAEMON S TARTED EACH MINUTE TO EXECUTE WHAT IS IN A USER ’ S crontab FILE  crontab T AKES AS INPUT A USER EDITED FILE U SED TO INSERT JOBS TO BE EXECUTED BY cron DAEMON crontab –r ( REMOVES CONTENT FROM A USER ’ S crontab FILE ) crontab –l ( LISTS CONTENT OF USER ’ S crontab FILE ) crontab ( LISTS CONTENT OF USER ’ S crontab FILE )

21 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE21 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd) CRONTAB file’s entry syntax: minutes, hours, days of month, month, days of week, command o M INUTES : 00 TO 59, CAN BE EXPRESSED AS A RANGE E. G., 00-15, or 0,15,30,45 o H OURS : 0 TO 23, # of hours o D AY IN MONTH : 0 TO MAX # DAYS IN MONTH o M ONTH : 1 TO 12 o D AYS OF WEEK : 0 TO 6, WHERE 0=S UNDAY o U SE ASTERISK (*) TO INDICATE ALL o U SE COMMA (,) TO INDICATE A SET OF VALUES o U SE HYPHEN (-) TO INDICATE A RANGE OF VALUES

22 10/08/2009 rwjBROOKDALE COMMUNITY COLLEGE22 S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd) E XAMPLES OF ENTRIES IN A crontab FILE minutes, hours, days of month, month, days of week, command 00-10 17 10,20,30 * 1,3 find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EITHER 3 DAYS OF THE MONTH OR M ONDAY AND W EDNESDAY OF EACH MONTH ) 55 17 * * 4 find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EVERY T HURSDAY AT 5:55 PM ) 0,30 * * * * find / -newer.last_time -print >backuplist ( E XECUTE THE COMMAND EVERY 3 O MINUTES ON THE HALF HOUR )

23 10/22/2009 rwjBROOKDALE COMMUNITY COLLEGE23 U TILITY FOR ONE TIME EXECUTION at - SAME DATE, FORMAT hhmm OR hh:mm at –t - SCHEDULED, FORMAT [[CC]YY]MMDDhhmm[.SS] $ at 15:08 at> empawk2.sh > rep.lst at –l- LISTS ITEMS IN “ at” QUEUE at -r - re MOVES ITEM FROM “ at” QUEUE at –m E XECUTE AS A BATCH JOB IN “at” QUEUE  B ATCH JOBS ARE RUN WHEN RESOURCE UTILIZATION LEVELS ARE LOW,  H AVE LOWER PRIORITY THAN USER FOREGROUND JOBS  S UBMITS JOB TO RUN IN BATCH QUEUE batch < empawk22.sh S CHEDULE A P ROCESS TO R UN A UTOMATICALLY (contd)

24 10/08/2009 rwjBROOKDALE COMMUNITY COLLEGE24 S UMMARY P ROCESS C YCLE  W HAT PARENT OR CHILD CAN DO WHILE OTHER IS RUNNING P ROGRAM STATUS COMMAND R UNNING A PROCESS  B ACKGROUND  F OREGROUND  T ERMINATE A PROCESSES CRON AND RELATED COMMANDS


Download ppt "U NIX C OMP -145 L ECTURE 5: UNIX P ROCESSES T EXT : S. D AS, “Y OUR U NIX : T HE ULTIMATE G UIDE ”, 2 ND E DITION, M C G RAW H ILL, 2006 10/22/2009 rwjBROOKDALE."

Similar presentations


Ads by Google