//Program
#include <stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<sys/stat.h>
#include<stdlib.h>
int main(int argc, char **argv)
{
int fd;
char *buffer;
char ch;
int i=0,ret;
//check if filename is given as argument to this program, otherwise
print message and exit
if(argc < 2)
{
printf("Usage: %s filename\n",argv[0]);
exit(-1);
}
//allocate memory for bufffer
buffer=(char*)malloc(100*sizeof(char));
//open file for reading
fd=open(argv[1],O_RDONLY);
if(fd < 0)
{
perror("read error: ");
exit(-2);
}
//read from file till EOF
while(read(fd,&ch,1 > 0))
{
if(ch == EOF)
break;
if(ch == '\n')
{
buffer[i]='\0';
printf("%s\n",buffer);
i=0;
}
buffer[i++]=ch;
}
buffer[i]='\0';
printf("%s\n",buffer);
return 0;
}
===============================
//output
Deadlock occurs when all of the following apply:
1. Mutual exclusion condition
2. Hold and wait condition
3. No pre-emption condition
4. Circular wait condition
In Unix/Linux, input and output are treated as files and referenced by the operating system using file descriptors. When you open a shell session, for example, three file descriptors are in use: 0 st...
UNIX is all about manipulating files and input/output streams fluidly, so it is important to get a strong grasp of how this fundamentally works at the system call level to understand higher-level system programming concepts. Every program automatically has three file descriptors opened by the shell standard input standard output standard error 1 2 One can use read and write other open file. Normally, standard input and output on the terminal are line-buffered, so, for example, the specified number of...
Purpose
This assignment should give you experience in using file
descriptors, open(), close(), write(), stat() and chmod(),
perror(), and command line arguments.
Program
Write a C++ program that will allow you to add messages to a
file that has NO permissions for any user.
A Unix system has many files that have sensitive information in
them. Permissions help keep these files secure. Some files can be
publicly read, but can not be altered by a regular user (ex.:
/etc/passwd). Other...
Using C++ in Visual Studios
Rewrite the code to use a Stack instead of a Queue. You will
need to think about the differences in the Stack and Queue. Think
about how they operate and how the nodes may differ.
Modify the code as necessary.
You will need to push to the Stack, pop from the Stack, peek at
the Stack. You will need a member functions like in the example
code. Your program will need to show that everything...