Professional Documents
Culture Documents
Practical Os
Practical Os
Practical Os
Step 1 − Create pipe1 for the parent process to write and the child process to read.
Step 2 − Create pipe2 for the child process to write and the parent process to read.
Step 3 − Close the unwanted ends of the pipe from the parent and child side.
Step 4 − Parent process to write a message and child process to read and display
on the screen.
Step 5 − Child process to write a message and parent process to read and display
on the screen.
Program
#include<stdio.h>
#include<unistd.h>
int main() {
int pipefds1[2], pipefds2[2];
int returnstatus1, returnstatus2;
int pid;
char pipe1writemessage[20] = "Hi";
char pipe2writemessage[20] = "Hello";
char readmessage[20];
returnstatus1 = pipe(pipefds1);
if (returnstatus1 == -1)
{
printf("Unable to create pipe 1 \n");
return 1;
}
returnstatus2 = pipe(pipefds2);
if (returnstatus2 == -1) {
printf("Unable to create pipe 2 \n");
return 1;
}
pid = fork();
Program
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/msg.h>
// structure for message queue
struct msg_buffer
{
long msg_type;
char msg[100];
} message;
main()
{
key_t my_key;
int msg_id;
my_key = ftok("progfile", 65);
msg_id = msgget(my_key, 0666 | IPC_CREAT);
message.msg_type = 1;
printf("Write Message : ");
fgets(message.msg, 100, stdin);
msgsnd(msg_id, &message, sizeof(message), 0);
printf("Sent message is : %s \n", message.msg);
}
Practical 10
1. tee – It reads from the standard input and writes to both standard output and one or
more files at the same time.
Syntax –
tee -a filename – used to append a file
2. pg – it displays the contents of text files, one page at a time.
Syntax –
pg [-number] [-p string] [-cefnrs] [+line] [+/pattern/] [file...]
3. comm –
compare two sorted files line by line and write to standard output
Syntax-
$comm [OPTION]... FILE1 FILE2
4. cmp –
used to compare the two files byte by byte and helps to find out whether the two
files are identical or not.
Syntax-
cmp [OPTION]... FILE1 [FILE2 [SKIP1 [SKIP2]]]
eg – cmp file1.txt file2.txt
000 No permission
13. ulimit- used to see, set, or limit the resource usage of the current user
Syntax- ulimit -a (for checking limit)
14. sort - used to sort a file
Syntax- $ sort filename.txt
15. grep – it searches a file for a particular pattern of characters
Syntax- grep [options] pattern [files]
16. egrep- egrep is a pattern searching command which belongs to the family of grep
functions
Syntax- egrep [ options ] 'PATTERN' files
17. fgrep - used to search for the fixed-character strings in a file.
Syntax- fgrep [options] [ -e pattern_list] [pattern] [file]
18. paste- It is used to join files horizontally
Syntax- paste [OPTION]... [FILES]...
19. join- used for joining lines of two files on a common field.
Syntax- $join [OPTION] FILE1 FILE2
20. du- used to find out the disk usage of set of files or a directory.
Syntax- du [OPTION]... [FILE]...
21. df - ( disk free), is used to display information related to file systems about total
space and available space.
Syntax- df [OPTION]... [FILE]...
22. ps- is used to list the currently running processes and their PIDs
Syntax - ps [options]
23. who- who command is used to find out the following information :
1. Time of last system boot
2. Current run level of the system
3. List of logged in users and more.
Syntax - $who [options] [filename]