Test Output:
RETURN VALUES
If successful, the number of bytes actually read is returned. Upon reading end-of-file, zero is returned. Otherwise, a -1 is returned and the global variable errno is set to indicate the error.
Name
write - write to a file descriptor Synopsis
#include <unistd.h>
ssize_t write(int fd, const void *buf, size_t count); Description
write() writes up to count bytes to the file referenced by the file descriptor fd from the buffer starting at buf. POSIX requires that a read() which can be proved to occur after a write() has returned returns the new data. Note that not all file systems are POSIX conforming.
Return Value
On success, the number of bytes written are returned (zero indicates nothing was written). On error, -1 is returned, and errno is set appropriately. If count is zero and the file descriptor refers to a regular file, 0 may be returned, or an error could be detected. For a special file, the results are not portable.
Errors EAGAIN
Non-blocking I/O has been selected using O_NONBLOCK and the write would block.
EBADF
fd is not a valid file descriptor or is not open for writing. EFAULT
buf is outside your accessible address space. EFBIG
An attempt was made to write a file that exceeds the implementation-defined maximum file size or the process' file size limit, or to write at a position past the maximum allowed offset.
EINTR
The call was interrupted by a signal before any data was written. EINVAL
fd is attached to an object which is unsuitable for writing; or the file was opened with the O_DIRECT flag, and either the address specified in buf, the value specified in count, or the current file offset is not suitably aligned.
EIO
A low-level I/O error occurred while modifying the inode. ENOSPC
The device containing the file referred to by fd has no room for the data. EPIPE
fd is connected to a pipe or socket whose reading end is closed. When this happens the writing process will also receive a SIGPIPE signal. (Thus, the write return value is seen only if the program catches, blocks or ignores this signal.) NAME
fork, fork1 - create a new process SYNOPSIS #include <sys/types.h> #include <unistd.h> pid_t fork(void); pid_t fork1(void); DESCRIPTION
The fork() and fork1() functions create a new process. The new process (child process) is an exact copy of the calling process (parent process). The child process inherits the following attributes from the parent process:
o real user ID, real group ID, effective user ID, effective group ID o environment
o open file descriptors
o close-on-exec flags (see exec(2))
o signal handling settings (that is, SIG_DFL, SIG_IGN, SIG_HOLD, function address)
o set-user-ID mode bit o set-group-ID mode bit o profiling on/off status o nice value (see nice(2))
o scheduler class (see priocntl(2))
o all attached shared memory segments (see shmop(2))
o process group ID -- memory mappings (see mmap(2))
o session ID (see exit(2)) o current working directory o root directory
o file mode creation mask (see umask(2))
SunOS 5.9 Last change: 23 Jul 2001 1 System Calls fork(2)
o resource limits (see getrlimit(2))
o controlling terminal
o saved user ID and group ID o task ID and project ID
o processor bindings (see processor_bind(2))
o processor set bindings (see pset_bind(2))
Scheduling priority and any per-process scheduling parameters that are specific to a given scheduling class may or may not be inherited according to the policy of that particular class (see priocntl(2)). The child process differs from the parent process in the following ways:
o The child process has a unique process ID which does not match any active process group ID.
o The child process has a different parent process ID (that is, the process ID of the parent process).
o The child process has its own copy of the parent's file descriptors and directory streams. Each of the child's file descriptors shares a common file pointer with the corresponding file descriptor of the parent.
o Each shared memory segment remains attached and the value of shm_nattach is incremented by 1.
o All semadj values are cleared (see semop(2)).
o Process locks, text locks, data locks, and other memory locks are not inherited by the child (see plock(3C) and memcntl(2)).
o The child process's tms structure is cleared:
tms_utime, stime, cutime, and cstime are set to 0 (see times(2)).
o The child processes resource utilizations are set to 0; see getrlimit(2). The
it_value and it_interval values for the ITIMER_REAL timer are reset to 0; see getitimer(2).
o The set of signals pending for the child process is initialized to the empty set. o Timers created by timer_create(3RT) are not inherited by the child process.
NAME
pipe -- create descriptor pair for interprocess communication
SYNOPSIS
#include <unistd.h> int
pipe(int *fildes);
DESCRIPTION
The pipe() function creates a pipe, which is an object allowing unidirec- tional data flow, and allocates a pair of file descriptors. The first
descriptor connects to the read end of the pipe, and the second connects to the write end, so that data written to fildes[1] appears on (i.e., can be read from) fildes[0]. This allows the output of one program to be sent to another program: the source's standard output is set up to be the write end of the pipe, and the sink's standard input is set up to be the read end of the pipe. The pipe itself persists until all its associated descriptors are closed.
A pipe whose read or write end has been closed is considered widowed. Writing on such a pipe causes the writing process to receive a SIGPIPE signal. Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count.
RETURN VALUES
On successful creation of the pipe, zero is returned. Otherwise, a value of -1 is returned and the variable errno set to indicate the error.
ERRORS
The pipe() call will fail if:
[EMFILE] Too many descriptors are active. [ENFILE] The system file table is full.
[EFAULT] The fildes buffer is in an invalid area of the process's address space.
Revised On: 22/06/2009 TITLE Client - Server communication using Inter process Communication:
PROBLEM
STATEMENT