What%20is%20a%20Process? - PowerPoint PPT Presentation

About This Presentation
Title:

What%20is%20a%20Process?

Description:

What is a Process? A process is an executing program and its necessary overhead ... The pointer is incremented by the amount of data read. Questions ... – PowerPoint PPT presentation

Number of Views:24
Avg rating:3.0/5.0
Slides: 12
Provided by: shivpa
Category:

less

Transcript and Presenter's Notes

Title: What%20is%20a%20Process?


1
What is a Process?
  • A process is an executing program and its
    necessary overhead
  • a process is not a program by itself

2
Overview
  • System Calls
  • fork()
  • wait()
  • pipe()
  • write()
  • read()
  • Examples

3
Process Creation
  • fork()
  • NAME
  • fork()- create a new process
  • SYNOPSIS
  • include ltsys/types.hgt
  • include ltunistd.hgt
  • ?pid_t fork (void)
  • RETURN VALUE
  • success
  • parent- child pid
  • child- 0
  • failure
  • -1

4
fork() system call-example
  • include ltsys/types.hgt
  • include ltunistd.hgt
  • include ltstdio.hgt
  • main()
  • printf ( ld parent process id ld\n,
    getpid(), getppid() )
  • fork()
  • printf ( \nld parent process id ld\n,
    getpid(), getppid() )

5
fork() system call-example
  • 17619 parent process id 12729
  • 17619 parent process id 12729
  • 2372 parent process id 17619

6
fork()- program structure
  • include ltsys/types.hgt
  • include ltunistd.hgt
  • include ltstdlib.hgt
  • include ltstdio.hgt
  • main( int argc, char argv )
  • pid_t pid
  • if ( ( pid fork() ) gt 0 )
  • /parent/
  • else if ( pid 0 )
  • /child/
  • else
  • /cannot fork/
  • exit( 0 )

7
wait() system call
  • wait() - wait for the process whose pid reference
    is passed to finish executing
  • SYNOPSIS
  • include ltsys/types.hgt
  • include ltsys/wait.hgt
  • ?pid_t wait ( int stat_loc )
  • The unsigned decimal integer process ID for
    which to wait.
  • RETURN VALUE
  • success- child pid
  • failure- -1 and errno is set

8
wait()- program structure
include ltsys/types.hgt include
ltunistd.hgt include ltstdlib.hgt include
ltstdio.hgt main( int argc, char argv
) pid_t childPID if ( ( childPID fork() )
0 ) /child/ else /parent/ wa
it ( 0 ) exit( 0 )
9
pipe() system call
  • pipe() - to create a read-write pipe that may
    later be used to communicate with a process we'll
    fork off.
  • SYNOPSIS
  • int pipe( pfd )
  • int pfd2
  • PARAMETER
  • pfd is an array of 2 integers, which that will
    be used to save the two file descriptors used to
    access the pipe.
  • RETURN VALUE
  • 0 - success
  • -1 - error.

10
pipe() - structure
  • / first, define an array to store the two file
    descriptors /
  • int pipes2
  • / now, create the pipe /
  • int rc pipe(pipes)
  • if (rc -1) / pipe() failed /
  • perror("pipe")
  • exit(1)
  • If the call to pipe() succeeded, a pipe will be
    created, pipes0 will contain the number of its
    read file descriptor, and pipes1 will contain
    the number of its write file descriptor.

11
write() system call
  • write() - used to write data to a file or other
    object identified by a file descriptor.
  • SYNOPSIS
  • include ltsys/types.hgt
  • size_t write(int fildes, const void buf,
    size_t nbyte)
  • PARAMETER
  • fildes is the file descriptor,
  • buf is the base address of the area of memory
    that data is copied from,
  • nbyte is the amount of data to copy.
  • RETURN VALUE
  • The return value is the actual amont of data
    written, if this differs from nbyte then
    something has gone wrong.

12
read() system call
  • read() - read data from a file or other object
    identified by a file descriptor.
  • SYNOPSIS
  • include ltsys/types.hgt
  • size_t read(int fildes,void buf, size_t
    nbyte)
  • ARGUMENT
  • fildes is the descriptor,
  • buf is the base address of the memory area into
    which the data is read,
  • nbyte is the maximum amount of data to read.
  • RETURN VALUE
  • The actual amount of data read from the file.
    The pointer is incremented by the amount of data
    read.

13
Questions
Write a Comment
User Comments (0)
About PowerShow.com