SlideShare a Scribd company logo
1 of 58
UNIT -6  SIGNALS AND DAEMON PROCESSES  ,[object Object],[object Object],[object Object],[object Object]
Stack Heap Uninitialized data (bss) Initialized data Text Command line args and environment variables Initialized to zero by exec Read from program by exec
Variable  Standards- POSIX.1 Standards- XPG3 Implementation: SVR4 Implementation-4.3+BSD Description HOME     Home directory LANG    Name of locale LC_ALL    Name of locale LC_COLLATE    Name of locale for collation LC_CTYPE    Name of locale for character classification LC_MONETARY    Name of locale for monetary editing LC_NUMERIC    Name of locale for numeric editing LC_TIME    Name of locale for date/time formatting LOGNAME     Login name NLSPATH   Sequence of templates for message catalogs PATH     List of path prefixes to search for executable files TERM     Terminal type TZ     Time zone information
Function Std- ANSI C Std: POSIX.1 Std: XPG3 Impl: SVR4 Impl: 4.3BSD getenv      putenv (maybe)    setenv  unsetenv  clearenv (maybe)
#include <sys/time.h> #include <sys/resource.h> int getrlimit (int resource, struct rlimit *rlptr); int setrlimit (int resource, const struct rlimit *rlptr); struct rlimit{ rlim_t rlim_cur;  /*soft limit: current limit */ rlim_t rlim_max;  /* hard limit: maximum value for rlim_cur */ }; getrlimit and setrlimit functions
Rules ,[object Object],[object Object],[object Object],[object Object]
RLIMIT_CORE The maximum size in bytes of a core file RLIMIT_CPU The maximum amount of CPU time in seconds (SIGXCPU) RLIMIT_DATA The maximum size in bytes of the data segment RLIMIT_FSIZE The maximum size in bytes of a file that may be created (SIGFSZ) RLIMIT_MEMLOCK Locked-in memory address space RLIMIT_NOFILE The maximum number of open files per process RLIMIT_NPROC The maximum number of child processes per user id RLIMIT_OFILE Same as RLIMIT_NOFILE RLIMIT_RSS Maximum resident set size in bytes RLIMIT_STACK The maximum size in bytes of the stack RLIMIT_VMEM The maximum size in bytes of the mapped address space
#include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> #include &quot;ourhdr.h&quot; #define doit(name) prlimits(#name, name)  static void prlimits(char *, int); int main (void)  { doit(RLIMIT_CORE);  doit(RLIMIT_CPU);  doit(RLIMIT_DATA);  doit(RLIMIT_FSIZE); #ifdef RLIMIT MEMLOCK doit(RLIMIT_MEMLOCK); #endif #ifdef RLIMIT_NOFILE  /* SVR4 name */ doit(RLIMIT_NOFILE); #endif #ifdef RLIMIT_OFILE /* 4.3+BSD name */ doit(RLIMIT_OFILE); #endif #ifdef RLIMIT_NPROC doit(RLIMIT_NPROC); #endif #ifdef RLIMIT_RSS doit(RLIMIT RSS); #endif doit(RLIMIT_STACK); #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM); #endif exit(0); }
static void pr_limits (char *name, int resource) { struct rlimit limit ; if (getrlimit(resource, &limit) < 0) err_sys(&quot;getrlimit error for %S&quot;, name); printf (&quot;%-14s &quot;, name);  if (limit.rlim_cur == RLIM_INFINITY) printf(&quot; (infinite) &quot;); else printf(&quot;%10ld &quot;, limit.rlim_cur); if (limit.rlim_max == RLIM_INFINITY) printf(&quot; (infinite)&quot;); else printf(&quot;%10ld&quot;, limit.rlim_max); }
Output – SVR4 RLIMIT_CORE 1048576 1048576 RLIMIT_CPU (infinite) (infinite) RLIMIT_DATA 16777216 16777216 RLIMIT_FSIZE 2097152 2097152 RLIMIT_NOFILE 64 1024 RLIMIT_STACK 16777216 16777216 RLIMIT_VMEM 16777216 16777216
UNIX Kernel Support for Processes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
File descriptor table current directory root … . Text Data Stack Process U-area A Process Process Table Per-process region table A UNIX process data structure Kernel region Table
UNIX Kernel Support for Processes ,[object Object],[object Object],[object Object],[object Object]
Process Table Data Structure of Parent and child after fork Kernel region Table Text Data Stack Stack Data File desc table File desc table File Table Parent Child
UNIX Kernel Support for Processes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UNIX Kernel Support for Processes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
UNIX Kernel Support for Processes ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
int main (void) { pid_t pid; if ( (pid = fork() <0) err_sys(“fork error&quot;); else if (pid == 0) /* first child */ { if ( (pid = fork () < 0) err_sys(&quot;fork error&quot;); else if (pid > 0) exit (0);  /* parent from second fork == first child */ /* We're the second child; our parent becomes init as soon as our real parent calls  exit () in the statement above. Here's where we'd continue executing, knowing that when we're done, init will reap our status. */ sleep(2); printf (&quot; second child, parent pid = %d It, getppid () ) ; exit(0); } if (waitpid(pid, NULL, 0) != pid) /* wait for first child */   err_sys(&quot;waitpid error&quot;); /* We're the parent (the original process); we continue executing,  knowing that we're not the parent of the second child. */ exit (0) ; }
Wait3 and Wait4 functions #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/resource.h> pid_t  wait3(int *statloc, int options, struct rusage *rusage); pid_t wait4(pid_t pid, int *statloc, int options, struct rusage *rusage); Function Pid Options Rusage POSIX.1 SVR4 4.3+BSD wait waitpid wait3 wait 4
Race Conditions ,[object Object],[object Object],[object Object],[object Object],[object Object]
#include &quot;ourhdr.h&quot; TELL_WAIT () ; /* set things up for TELL xxx & WAIT xxx */ if ( (pid = fork () < 0) err_sys(&quot;fork error&quot;); else if (pid == 0) { /* child */ /* child does whatever is necessary... */ TELL_PARENT(getppid()); /* tell parent we're done */ WAIT_PARENT () ; /* and wait for parent */ /* and the child continues on its way... */  exit(0); } /* parent does whatever is necessary... */ TELL_CHILD (pid) ;  /* tell child we're done */ WAIT_CHILD () ; /* and wait for child */ /* and the parent continues on its way... */  exit (0) ;
#include <sys/types. h>  #include &quot;ourhdr.h&quot; static void charatatime (char *); int main (void) { pid_t pid; if ( (pid = fork () < 0) err_sys (&quot;fork error&quot;); else if (pid == 0) { charatatime (&quot;output from child&quot;); ) else { charatatime(.&quot;output from parent&quot;); )  exit(0) ; } static void charatatime (char *str)  { char *ptr; int c; setbuf (stdout, NULL); /* set unbuffred */ for (ptr = str; c = *ptr++; ) putc(c, stdout); }
Output  $ a.out output from child output from parent $ a.out oouuttppuutt ffrroomm cphairledn t $ a.out oouuttppuutt ffrroomm pcahrielndt $ a.out ooutput from parent utput from child
int main (void) { pid_t pid; +  TELL_WAIT () ; + if ( (pid = fork() < 0) err_sys(&quot;fork error&quot;); else if (pid == 0) { + WAIT_PARENT(); /* parent goes first */ charatatime(&quot;output from child&quot;); } else { charatatime(&quot;output from parent&quot;); + TELL_CHILD(pid); } exit (0) ; } static void charatatime(char *str) { char *ptr; int c; setbuf(stdout, NULL); /* set unbuffered */ for (ptr = str; c = *ptr++;) putc(c, stdout); }
#include <unistd. h> int execl ( const char *pathname ,  const char *arg0, ... / * (char *) 0 * /  ); int execv ( const char *pathname ,  char *const argv[ ]  ) ; int execle ( const char *pathname ,  const char *arg0, .../* (char *) 0,  char *const envp[ ] */ ); int execve ( const char *pathname ,  char *const argv[ ],  char *const envp[ ] ) ; int execlp( const char *filename ,  const char *argO, ... /* (char *) 0 */  ); int execvp ( const char *filename ,  char *const argv [ ]  ) ; All six return: -1 on error, no return on success exec Functions ,[object Object],[object Object],[object Object]
Differences Limit on the total size of the argument list : ARG_MAX 4096 on a POSIX.1 system. Eg: grep _POSIX_SOURCE /usr/include/*/*.h Function pathname filename arg list argv[ ] environ emp[ ] execl execlp execle execv execvp execve (Letter in name) P L V e
Inherits ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Relationship execlp execl execle execvp execv execve (system call) build argv try each PATH prefix use environ build argv build argv
char *env_init[] = { &quot;USER=unknown&quot;, &quot;PATH=/tmp&quot;, NULL }; int main (void) { pid_t  pid; if ( (pid = fork () < 0) err_sys (&quot; fork error&quot;); else if (pid == 0) { /* specify pathname, specify environment */ if (execle (&quot; /home/stevens/bin/echoall&quot;, &quot;echoall&quot;, &quot;myarg1&quot;, &quot;MY ARG2&quot;, (char *) 0, env_init < 0) err_sys(&quot;execle error&quot;); } if (waitpid(pid, NULL, 0) < 0) err_sys (&quot;wait error&quot;); if ( (pid = fork () < 0) err_sys (&quot;fork error&quot;); else if (pid == 0) {   /* specify filename, inherit environment */ if (execlp(&quot;echoall“,&quot;echoall&quot;, &quot;only 1 arg&quot;, (char *) 0) < 0) err_sys(&quot;execlp error&quot;); } exit (0) ; }
#include &quot;ourhdr.h&quot; int main(int argc, char *argv[]) { int i; char **ptr; extern char **environ; for (i = 0; i < argc; i++) /* echo all command-line args */ printf(&quot;argv[%d]: %s&quot;, i, argv[i]); for (ptr = environ; *ptr != 0; ptr++) printf(&quot;%s&quot;, *ptr); /* and all env strings *f exit (0) ; }
$ a.out argv[0]: echoall argv[l]: myarg1  argv[2]: MY ARG2  USER=unknown PATH=/tmp $ argv[0]: echoall argv[1]: only 1 arg USER=stevens HOME=/home/stevens LOGNAME=stevens 31 more lines……. EDITOR=/usr/ucb/vi
int system(const char *cmdstring) { pid_t  pid; int  status; if (cmdstring == NULL) return(1);  /* always a command processor with UNIX */ if ((pid = fork()) < 0) { status = -1;  /* probably out of processes */ } else if (pid == 0) {  /* child */ execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-c&quot;, cmdstring, (char *)0); _exit(127);  /* execl error */ } else {  /* parent */ while (waitpid(pid, &status, 0) < 0) { if (errno != EINTR) { status = -1; /* error other than EINTR from waitpid() */ break; } } } return(status); }
Exit Code Number Meaning Example Comments 1 catchall for general errors let &quot;var1 = 1/0&quot; miscellaneous errors, such as &quot;divide by zero&quot; 2 misuse of shell builtins, according to Bash documentation Seldom seen, usually defaults to exit code 1 126 command invoked cannot execute permission problem or command is not an executable 127 &quot;command not found&quot; possible problem with $PATH or a typo 128 invalid argument to  exit exit 3.14159 exit  takes only integer args in the range 0 - 255 128+n fatal error signal &quot;n&quot; kill -9  $PPIDof script $?  returns 137 (128 + 9) 130 script terminated by Control-C Control-C is fatal error signal 2, (130 = 128 + 2, see above) 255 exit status out of range exit -1 exit  takes only integer args in the range 0 - 255
Process Times ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Main program ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function to execute the command  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Function to calculate and print the time ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Output ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Interpreter files ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],$ cat /home/stevens/bin/testinterp #!/home/stevens/bin/echoarg foo $ a.out argv[0] : /home/stevens/bin/echoarg argv[1] :  foo argv[2] : /home/stevens/bin/testinterp argv[3] : myargl argv[4] : MY ARG2
Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Are interpreter files required? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Process Accounting ,[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Accounting Record
ac_Flag ,[object Object],[object Object],[object Object],[object Object],[object Object]
int main (void) { pid_t pid; if ( (pid = fork ()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { /* parent */ sleep(2); exit(2); /* terminate with exit status 2 */ } /* first. child */ if ( (pid =  fork()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0)  { sleep(4); abort (); /* terminate with core dump */ } /* second child */ if ( (pid = fork()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { execl (&quot; /usr/bin/dd&quot;, &quot;dd&quot;, &quot;if=/boot&quot;, &quot;of=/dev/null&quot;,NULL) exit(7); /* shouldn't get here */ /* third child */ if ( (pid = fork ()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { sleep(8); exit(0); /* normal exit */ } /* fourth child */ sleep(6); kill(getpid(), SIGKILL);  /* terminate with signal,  no core dump */ exit(6); /* shouldn't get here */ }
Procedure ,[object Object],[object Object],[object Object],[object Object]
Output ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Process Relationships ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Terminal Login init init getty Login Terminal device driver User at a terminal fork exec exec fd 0, 1, 2 RS-232 connection Reads /etc/ttys; Forks once per terminal Create empty environment Each child execs getty Reads user name Initial environment set Validate password Changes to home directory Permissions set ,[object Object],[object Object]
Network Login init inetd inetd telnetd Login shell Pseudo-terminal device driver User at a terminal TCP connection request From TELNET client fork exec fd 0, 1, 2 Executes /etc/rc When connection request arrives Network connection through telnetd server and telnet client telnet  hostname
Process Groups ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Sessions Login shell proc1 proc2 proc3 proc4 proc5 Process group Process group Process group session proc1 | proc2 & Proc3 | proc4 | proc5 ,[object Object]
Sessions ,[object Object],#include <sys/types.h> #include <unistd.h> pid_t setsid(void); ,[object Object],[object Object],[object Object]
Controlling Terminal ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Controlling Terminal Login shell proc1 proc2 proc3 proc4 proc5 Background Process group session leader = controlling prcess Background Process group Foreground Process group Controlling terminal Terminal input and terminal generated signals Modem disconnect (hangup signal)
tcgetpgrp and tcsetpgrp functions ,[object Object],[object Object],[object Object],[object Object]

More Related Content

What's hot

File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C ProgrammingRavindraSalunke3
 
Unit 8
Unit 8Unit 8
Unit 8siddr
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Moriyoshi Koizumi
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol ResolutionKen Kawamoto
 
4Developers 2018: The turbulent road to byte-addressable storage support at t...
4Developers 2018: The turbulent road to byte-addressable storage support at t...4Developers 2018: The turbulent road to byte-addressable storage support at t...
4Developers 2018: The turbulent road to byte-addressable storage support at t...PROIDEA
 
C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debuggingsplix757
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : PythonOpen Gurukul
 
The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88Mahmoud Samir Fayed
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
Ekon bestof rtl_delphi
Ekon bestof rtl_delphiEkon bestof rtl_delphi
Ekon bestof rtl_delphiMax Kleiner
 
More on Lex
More on LexMore on Lex
More on LexTech_MX
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2Kazuho Oku
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpen Gurukul
 

What's hot (20)

File Handling in C Programming
File Handling in C ProgrammingFile Handling in C Programming
File Handling in C Programming
 
Unit 8
Unit 8Unit 8
Unit 8
 
Hachiojipm11
Hachiojipm11Hachiojipm11
Hachiojipm11
 
Phpをいじり倒す10の方法
Phpをいじり倒す10の方法Phpをいじり倒す10の方法
Phpをいじり倒す10の方法
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol Resolution
 
Unit v
Unit vUnit v
Unit v
 
4Developers 2018: The turbulent road to byte-addressable storage support at t...
4Developers 2018: The turbulent road to byte-addressable storage support at t...4Developers 2018: The turbulent road to byte-addressable storage support at t...
4Developers 2018: The turbulent road to byte-addressable storage support at t...
 
Linux basics
Linux basicsLinux basics
Linux basics
 
C ISRO Debugging
C ISRO DebuggingC ISRO Debugging
C ISRO Debugging
 
OpenGurukul : Language : Python
OpenGurukul : Language : PythonOpenGurukul : Language : Python
OpenGurukul : Language : Python
 
The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88The Ring programming language version 1.3 book - Part 60 of 88
The Ring programming language version 1.3 book - Part 60 of 88
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Ekon bestof rtl_delphi
Ekon bestof rtl_delphiEkon bestof rtl_delphi
Ekon bestof rtl_delphi
 
More on Lex
More on LexMore on Lex
More on Lex
 
Отладка в GDB
Отладка в GDBОтладка в GDB
Отладка в GDB
 
Unix Programming with Perl 2
Unix Programming with Perl 2Unix Programming with Perl 2
Unix Programming with Perl 2
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
UNIX - Class1 - Basic Shell
UNIX - Class1 - Basic ShellUNIX - Class1 - Basic Shell
UNIX - Class1 - Basic Shell
 
Operating System Assignment Help
Operating System Assignment HelpOperating System Assignment Help
Operating System Assignment Help
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 

Viewers also liked

Unit 7
Unit 7Unit 7
Unit 7siddr
 
Part 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxTushar B Kute
 
Unix system programming
Unix system programmingUnix system programming
Unix system programmingSyed Mustafa
 
Unix operating system
Unix operating systemUnix operating system
Unix operating systemABhay Panchal
 

Viewers also liked (6)

Unit 7
Unit 7Unit 7
Unit 7
 
Prog ii
Prog iiProg ii
Prog ii
 
Usp notes unit6-8
Usp notes unit6-8Usp notes unit6-8
Usp notes unit6-8
 
Part 03 File System Implementation in Linux
Part 03 File System Implementation in LinuxPart 03 File System Implementation in Linux
Part 03 File System Implementation in Linux
 
Unix system programming
Unix system programmingUnix system programming
Unix system programming
 
Unix operating system
Unix operating systemUnix operating system
Unix operating system
 

Similar to Signals and Daemons

Introduction to Kernel Programming
Introduction to Kernel ProgrammingIntroduction to Kernel Programming
Introduction to Kernel ProgrammingAhmed Mekkawy
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Robert Stern
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docxfestockton
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryMike Lively
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineMatt Provost
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdfajay1317
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution planspaulguerin
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfclarityvision
 
1032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.21032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.2Stanley Ho
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstackThierry Gayet
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bChereCheek752
 

Similar to Signals and Daemons (20)

Sysprog 11
Sysprog 11Sysprog 11
Sysprog 11
 
Sysprog17
Sysprog17Sysprog17
Sysprog17
 
Introduction to Kernel Programming
Introduction to Kernel ProgrammingIntroduction to Kernel Programming
Introduction to Kernel Programming
 
Os lab final
Os lab finalOs lab final
Os lab final
 
Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1Golang basics for Java developers - Part 1
Golang basics for Java developers - Part 1
 
assign4assign4_part1bonnie.c This is a file system ben.docx
assign4assign4_part1bonnie.c  This is a file system ben.docxassign4assign4_part1bonnie.c  This is a file system ben.docx
assign4assign4_part1bonnie.c This is a file system ben.docx
 
PHP CLI: A Cinderella Story
PHP CLI: A Cinderella StoryPHP CLI: A Cinderella Story
PHP CLI: A Cinderella Story
 
CompilersAndLibraries
CompilersAndLibrariesCompilersAndLibraries
CompilersAndLibraries
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
Gps c
Gps cGps c
Gps c
 
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf  proxyc  CSAPP Web proxy   NAME    IMPORTANT Giv.pdf
proxyc CSAPP Web proxy NAME IMPORTANT Giv.pdf
 
Sysprog 16
Sysprog 16Sysprog 16
Sysprog 16
 
Sydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plansSydney Oracle Meetup - execution plans
Sydney Oracle Meetup - execution plans
 
Shell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdfShell to be modified#include stdlib.h #include unistd.h .pdf
Shell to be modified#include stdlib.h #include unistd.h .pdf
 
1032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.21032 cs208 g operation system ip camera case share.v0.2
1032 cs208 g operation system ip camera case share.v0.2
 
Pig workshop
Pig workshopPig workshop
Pig workshop
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the bfinalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
finalprojtemplatev5finalprojtemplate.gitignore# Ignore the b
 
process creation OS
process creation OSprocess creation OS
process creation OS
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 

Signals and Daemons

  • 1.
  • 2. Stack Heap Uninitialized data (bss) Initialized data Text Command line args and environment variables Initialized to zero by exec Read from program by exec
  • 3. Variable Standards- POSIX.1 Standards- XPG3 Implementation: SVR4 Implementation-4.3+BSD Description HOME     Home directory LANG    Name of locale LC_ALL    Name of locale LC_COLLATE    Name of locale for collation LC_CTYPE    Name of locale for character classification LC_MONETARY    Name of locale for monetary editing LC_NUMERIC    Name of locale for numeric editing LC_TIME    Name of locale for date/time formatting LOGNAME     Login name NLSPATH   Sequence of templates for message catalogs PATH     List of path prefixes to search for executable files TERM     Terminal type TZ     Time zone information
  • 4. Function Std- ANSI C Std: POSIX.1 Std: XPG3 Impl: SVR4 Impl: 4.3BSD getenv      putenv (maybe)    setenv  unsetenv  clearenv (maybe)
  • 5. #include <sys/time.h> #include <sys/resource.h> int getrlimit (int resource, struct rlimit *rlptr); int setrlimit (int resource, const struct rlimit *rlptr); struct rlimit{ rlim_t rlim_cur; /*soft limit: current limit */ rlim_t rlim_max; /* hard limit: maximum value for rlim_cur */ }; getrlimit and setrlimit functions
  • 6.
  • 7. RLIMIT_CORE The maximum size in bytes of a core file RLIMIT_CPU The maximum amount of CPU time in seconds (SIGXCPU) RLIMIT_DATA The maximum size in bytes of the data segment RLIMIT_FSIZE The maximum size in bytes of a file that may be created (SIGFSZ) RLIMIT_MEMLOCK Locked-in memory address space RLIMIT_NOFILE The maximum number of open files per process RLIMIT_NPROC The maximum number of child processes per user id RLIMIT_OFILE Same as RLIMIT_NOFILE RLIMIT_RSS Maximum resident set size in bytes RLIMIT_STACK The maximum size in bytes of the stack RLIMIT_VMEM The maximum size in bytes of the mapped address space
  • 8. #include <sys/types.h> #include <sys/time.h> #include <sys/resource.h> #include &quot;ourhdr.h&quot; #define doit(name) prlimits(#name, name) static void prlimits(char *, int); int main (void) { doit(RLIMIT_CORE); doit(RLIMIT_CPU); doit(RLIMIT_DATA); doit(RLIMIT_FSIZE); #ifdef RLIMIT MEMLOCK doit(RLIMIT_MEMLOCK); #endif #ifdef RLIMIT_NOFILE /* SVR4 name */ doit(RLIMIT_NOFILE); #endif #ifdef RLIMIT_OFILE /* 4.3+BSD name */ doit(RLIMIT_OFILE); #endif #ifdef RLIMIT_NPROC doit(RLIMIT_NPROC); #endif #ifdef RLIMIT_RSS doit(RLIMIT RSS); #endif doit(RLIMIT_STACK); #ifdef RLIMIT_VMEM doit(RLIMIT_VMEM); #endif exit(0); }
  • 9. static void pr_limits (char *name, int resource) { struct rlimit limit ; if (getrlimit(resource, &limit) < 0) err_sys(&quot;getrlimit error for %S&quot;, name); printf (&quot;%-14s &quot;, name); if (limit.rlim_cur == RLIM_INFINITY) printf(&quot; (infinite) &quot;); else printf(&quot;%10ld &quot;, limit.rlim_cur); if (limit.rlim_max == RLIM_INFINITY) printf(&quot; (infinite)&quot;); else printf(&quot;%10ld&quot;, limit.rlim_max); }
  • 10. Output – SVR4 RLIMIT_CORE 1048576 1048576 RLIMIT_CPU (infinite) (infinite) RLIMIT_DATA 16777216 16777216 RLIMIT_FSIZE 2097152 2097152 RLIMIT_NOFILE 64 1024 RLIMIT_STACK 16777216 16777216 RLIMIT_VMEM 16777216 16777216
  • 11.
  • 12. File descriptor table current directory root … . Text Data Stack Process U-area A Process Process Table Per-process region table A UNIX process data structure Kernel region Table
  • 13.
  • 14. Process Table Data Structure of Parent and child after fork Kernel region Table Text Data Stack Stack Data File desc table File desc table File Table Parent Child
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. int main (void) { pid_t pid; if ( (pid = fork() <0) err_sys(“fork error&quot;); else if (pid == 0) /* first child */ { if ( (pid = fork () < 0) err_sys(&quot;fork error&quot;); else if (pid > 0) exit (0); /* parent from second fork == first child */ /* We're the second child; our parent becomes init as soon as our real parent calls exit () in the statement above. Here's where we'd continue executing, knowing that when we're done, init will reap our status. */ sleep(2); printf (&quot; second child, parent pid = %d It, getppid () ) ; exit(0); } if (waitpid(pid, NULL, 0) != pid) /* wait for first child */ err_sys(&quot;waitpid error&quot;); /* We're the parent (the original process); we continue executing, knowing that we're not the parent of the second child. */ exit (0) ; }
  • 20. Wait3 and Wait4 functions #include <sys/types.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/resource.h> pid_t wait3(int *statloc, int options, struct rusage *rusage); pid_t wait4(pid_t pid, int *statloc, int options, struct rusage *rusage); Function Pid Options Rusage POSIX.1 SVR4 4.3+BSD wait waitpid wait3 wait 4
  • 21.
  • 22. #include &quot;ourhdr.h&quot; TELL_WAIT () ; /* set things up for TELL xxx & WAIT xxx */ if ( (pid = fork () < 0) err_sys(&quot;fork error&quot;); else if (pid == 0) { /* child */ /* child does whatever is necessary... */ TELL_PARENT(getppid()); /* tell parent we're done */ WAIT_PARENT () ; /* and wait for parent */ /* and the child continues on its way... */ exit(0); } /* parent does whatever is necessary... */ TELL_CHILD (pid) ; /* tell child we're done */ WAIT_CHILD () ; /* and wait for child */ /* and the parent continues on its way... */ exit (0) ;
  • 23. #include <sys/types. h> #include &quot;ourhdr.h&quot; static void charatatime (char *); int main (void) { pid_t pid; if ( (pid = fork () < 0) err_sys (&quot;fork error&quot;); else if (pid == 0) { charatatime (&quot;output from child&quot;); ) else { charatatime(.&quot;output from parent&quot;); ) exit(0) ; } static void charatatime (char *str) { char *ptr; int c; setbuf (stdout, NULL); /* set unbuffred */ for (ptr = str; c = *ptr++; ) putc(c, stdout); }
  • 24. Output $ a.out output from child output from parent $ a.out oouuttppuutt ffrroomm cphairledn t $ a.out oouuttppuutt ffrroomm pcahrielndt $ a.out ooutput from parent utput from child
  • 25. int main (void) { pid_t pid; + TELL_WAIT () ; + if ( (pid = fork() < 0) err_sys(&quot;fork error&quot;); else if (pid == 0) { + WAIT_PARENT(); /* parent goes first */ charatatime(&quot;output from child&quot;); } else { charatatime(&quot;output from parent&quot;); + TELL_CHILD(pid); } exit (0) ; } static void charatatime(char *str) { char *ptr; int c; setbuf(stdout, NULL); /* set unbuffered */ for (ptr = str; c = *ptr++;) putc(c, stdout); }
  • 26.
  • 27. Differences Limit on the total size of the argument list : ARG_MAX 4096 on a POSIX.1 system. Eg: grep _POSIX_SOURCE /usr/include/*/*.h Function pathname filename arg list argv[ ] environ emp[ ] execl execlp execle execv execvp execve (Letter in name) P L V e
  • 28.
  • 29. Relationship execlp execl execle execvp execv execve (system call) build argv try each PATH prefix use environ build argv build argv
  • 30. char *env_init[] = { &quot;USER=unknown&quot;, &quot;PATH=/tmp&quot;, NULL }; int main (void) { pid_t pid; if ( (pid = fork () < 0) err_sys (&quot; fork error&quot;); else if (pid == 0) { /* specify pathname, specify environment */ if (execle (&quot; /home/stevens/bin/echoall&quot;, &quot;echoall&quot;, &quot;myarg1&quot;, &quot;MY ARG2&quot;, (char *) 0, env_init < 0) err_sys(&quot;execle error&quot;); } if (waitpid(pid, NULL, 0) < 0) err_sys (&quot;wait error&quot;); if ( (pid = fork () < 0) err_sys (&quot;fork error&quot;); else if (pid == 0) { /* specify filename, inherit environment */ if (execlp(&quot;echoall“,&quot;echoall&quot;, &quot;only 1 arg&quot;, (char *) 0) < 0) err_sys(&quot;execlp error&quot;); } exit (0) ; }
  • 31. #include &quot;ourhdr.h&quot; int main(int argc, char *argv[]) { int i; char **ptr; extern char **environ; for (i = 0; i < argc; i++) /* echo all command-line args */ printf(&quot;argv[%d]: %s&quot;, i, argv[i]); for (ptr = environ; *ptr != 0; ptr++) printf(&quot;%s&quot;, *ptr); /* and all env strings *f exit (0) ; }
  • 32. $ a.out argv[0]: echoall argv[l]: myarg1 argv[2]: MY ARG2 USER=unknown PATH=/tmp $ argv[0]: echoall argv[1]: only 1 arg USER=stevens HOME=/home/stevens LOGNAME=stevens 31 more lines……. EDITOR=/usr/ucb/vi
  • 33. int system(const char *cmdstring) { pid_t pid; int status; if (cmdstring == NULL) return(1); /* always a command processor with UNIX */ if ((pid = fork()) < 0) { status = -1; /* probably out of processes */ } else if (pid == 0) { /* child */ execl(&quot;/bin/sh&quot;, &quot;sh&quot;, &quot;-c&quot;, cmdstring, (char *)0); _exit(127); /* execl error */ } else { /* parent */ while (waitpid(pid, &status, 0) < 0) { if (errno != EINTR) { status = -1; /* error other than EINTR from waitpid() */ break; } } } return(status); }
  • 34. Exit Code Number Meaning Example Comments 1 catchall for general errors let &quot;var1 = 1/0&quot; miscellaneous errors, such as &quot;divide by zero&quot; 2 misuse of shell builtins, according to Bash documentation Seldom seen, usually defaults to exit code 1 126 command invoked cannot execute permission problem or command is not an executable 127 &quot;command not found&quot; possible problem with $PATH or a typo 128 invalid argument to exit exit 3.14159 exit takes only integer args in the range 0 - 255 128+n fatal error signal &quot;n&quot; kill -9 $PPIDof script $? returns 137 (128 + 9) 130 script terminated by Control-C Control-C is fatal error signal 2, (130 = 128 + 2, see above) 255 exit status out of range exit -1 exit takes only integer args in the range 0 - 255
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47. int main (void) { pid_t pid; if ( (pid = fork ()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { /* parent */ sleep(2); exit(2); /* terminate with exit status 2 */ } /* first. child */ if ( (pid = fork()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { sleep(4); abort (); /* terminate with core dump */ } /* second child */ if ( (pid = fork()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { execl (&quot; /usr/bin/dd&quot;, &quot;dd&quot;, &quot;if=/boot&quot;, &quot;of=/dev/null&quot;,NULL) exit(7); /* shouldn't get here */ /* third child */ if ( (pid = fork ()) < 0) err_sys(&quot;fork error&quot;); else if (pid != 0) { sleep(8); exit(0); /* normal exit */ } /* fourth child */ sleep(6); kill(getpid(), SIGKILL); /* terminate with signal, no core dump */ exit(6); /* shouldn't get here */ }
  • 48.
  • 49.
  • 50.
  • 51.
  • 52. Network Login init inetd inetd telnetd Login shell Pseudo-terminal device driver User at a terminal TCP connection request From TELNET client fork exec fd 0, 1, 2 Executes /etc/rc When connection request arrives Network connection through telnetd server and telnet client telnet hostname
  • 53.
  • 54.
  • 55.
  • 56.
  • 57. Controlling Terminal Login shell proc1 proc2 proc3 proc4 proc5 Background Process group session leader = controlling prcess Background Process group Foreground Process group Controlling terminal Terminal input and terminal generated signals Modem disconnect (hangup signal)
  • 58.