int posix_spawn_vp(
pid_t *restrict pid, //pointer to the process id of the process it spawns for.
char const *restrict file, //character pointer for name of the file used to perform the execvp function.
posix_spawnattr_t const *att, //specify set of actions which define the process start up behavior.
char * const restrict argv, //Arguments to be passed to the subsidiary program execvp.
char * const restrict envp // Environment variables.
);
Note: The “restrict” keyword represents annotation of c level. The caller when it uses the restrict keyword,it “promises” not to point to other storage location which are already pointed by other pointers.
Facilitates spontaneous data generation only. | Facilitates request response protocol based data generation. |
Virtually can support infinite amount of storage. | Limited storage capacity. |
ssize_t read( // Opens file with descriptor fd, reads count no of bytes in to the buffer specified by the character pointer.
int fd, //file descriptor.
void *buffer, // address of a buffer to read into.
size_t count, //No of bytes to read.Buffers minimum size.
);
ssize_t write( // write count no of bytes from the input buffer to the file with descriptor fd
int fd, //file descriptor.
void *buffer, // address of a buffer to write from.
size_t count, //No of bytes to write.
);
ssize_t lseek( // move the read/write file offset for the file specified using the descriptor
int fd, //file descriptor.
off_t offset, // offset value.
int whence, // If SEEK_SET,then file offset = offset bytes.If SEEK_CUR, then file offset = current location + offset. If SEEK_END,then file offset = file size + offset
);
ssize_t pread( //
int fd, //file descriptor.
void *buf, // input buffer pointer.
size_t nbyte, // Number of bytes
off_t offset, // offset value.
);
int open( //
char const *file, //Character pointer to the file name.
int flags, // Specifies open mode.(O_RDONLY,O_RDWR,O_WRONLY,O_EXEC,O_SEARCH)
... // variable number of arguments based on the value for flags
);
int close(int fd) //Specifies file descriptor to be closed
cat foo >file 2>&1 //stdout points to a file and stderr points to the clone
int fd1 = open("file1",0_WRONLY);
int fd2 = open("file2",0_WRONLY);
int fd2 = dup(fd1);
close(0);
close(1);
close(2);
open("/deb/null",O_RDONLY); //returns 0
fd2=dup(fd) // we get 1
But on the downside, this works if we are doing only this and nothing else. With respect to performance keep in mind, open("/dev/null") slower than open("/").
int fd=open("file",O_WRONLY)
dup2(fd,1)
dup2(fd,2)
close(fd)
int fd = open("/tmp/sort",O_RDWR|O_CREATE|O_TRUNC,0666);//Create a temp tile
if(fd<0) error();
if(unlink("/tmp/sort")!=0) error();//if opened again, it wont affect our file
char name[100];
long pid = getpid();
sprintf(name,"/tmp/sort %ld",pid);//no collision between processes
if (fd<0) error();
compute(fd);
if(close(fd)!=0) error();
if(unlink(name)!=0) error();
char buf[100];
generate_random_file_name(buf);
while{if(stat(buf,&st) == 0) } ;
int fd = open(buf,O_RDWR | O_CREAT | O_TRUNC,0666);
do {
generate_random_file_name(buf);
} while((fd = open(buf,O_RDWR | O_CREAT | O_TRUNC | O_EXCL,0666)<0 && errno == EEXIST);