slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
資訊系統原理作業二補充說明 PowerPoint Presentation
Download Presentation
資訊系統原理作業二補充說明

Loading in 2 Seconds...

play fullscreen
1 / 5

資訊系統原理作業二補充說明 - PowerPoint PPT Presentation


  • 70 Views
  • Uploaded on

資訊系統原理作業二補充說明. fork() – create a child process #include <sys/types.h> #include <unistd.h> pid_t fork(void) Returns: 0 in child process ID of child (>0) in parent -1 on error. fork(). A Simple Example: … pid_t pid = fork (); if (pid<0 ) /* error */ { … }

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '資訊系統原理作業二補充說明' - whoopi-grant


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide1
資訊系統原理作業二補充說明
  • fork() – create a child process
    • #include <sys/types.h>
    • #include <unistd.h>
    • pid_t fork(void)
  • Returns:
    • 0 in child
    • process ID of child (>0) in parent
    • -1 on error
slide2
fork()
  • A Simple Example:

pid_t pid = fork();

if (pid<0) /* error */

{ … }

else if (pid == 0) /* child */

{ … }

else /* parent */

{ … }

pipe 1 2
Pipe (1/2)
  • Pipes:
    • The oldest (and most commonly used) form of UNIX IPC (Inter-Process Communication)
    • half-duplex (data flows only in one direction)
    • Can be used only between processes that have a common ancestor
pipe 2 2
Pipe (2/2)
  • pipe() – Create a pipe
    • #include <unistd.h>
    • int pipe(int fd[2]);
    • Returns: 0 if OK, -1 on error.
    • fd[0]: for reading, fd[1]: for writing
  • Close unnecessary fds
  • Read(fd[0])
  • Write(fd[1])
references
References
  • Advanced Programming in the UNIX Environment, by W. Richard Stevens, Addison-Wesley.
  • Manual pages on UNIX systems:
    • man fork
    • man pipe