0% found this document useful (0 votes)
49 views

Linux Assgnment (System Calls, Shell Scripting, Filter)

The document outlines topics for a Linux assignment including system calls, shell scripting, and filters. For system calls, 13 programs are listed that involve getting process information, invoking commands, demonstrating fork functionality, and checking exit status. For shell scripting, 11 scripts are listed involving login messages, menus, arithmetic questions, file operations, and contact management. Finally, 10 common Linux filters like cat, head, tail, sort, grep, sed, and nl are described.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Linux Assgnment (System Calls, Shell Scripting, Filter)

The document outlines topics for a Linux assignment including system calls, shell scripting, and filters. For system calls, 13 programs are listed that involve getting process information, invoking commands, demonstrating fork functionality, and checking exit status. For shell scripting, 11 scripts are listed involving login messages, menus, arithmetic questions, file operations, and contact management. Finally, 10 common Linux filters like cat, head, tail, sort, grep, sed, and nl are described.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Linux Assignment

(Topics : System Calls, Shell Scripting, Filters)

(Roll No. 40814504418)

System Calls

1. Write a program to get the parent and the process id.

2. Write a program to check if the process is within if or else.


3. Write a program to invoke linux commands with C program.

4. Write a program to show the working of execvp.


5. Write the program to see the functionality of the fork.
6. Write a program for orphan process –where the parent terminates before child.

7. Write a program for zombies.


8. Write a program to test the process for sleeping beauty.
9. Write a program for time slicing.

10. Write a program to check for the exit status


11. Write a program to check the exit status using sleep and exit

12. Write a program to check whether the code is dumped or not.


13. Write a program to show child process value change.
Shell Scripting

1. Write a shell script that gets executed the moment user logs in. It should display the message: Good
Morning / Good afternoon /Good Evening depending upon the time user logs in.

2. Write a menu driven program which has the following options:


1) Contents of /etc/passwd
2) List of users who have currently logged in
3) Present working directory
4) Exit
3. Write a shell script that displays the following five questions one at a time:
1) How much is 10 + 5?
2) How much is 12 - 7?
3) How much is 15 / 5?
4) How much is 5 * 5?
5) How much is 10 % 4?
And compares the answer keyed in by the respondent with the right answer. If the answer is correct,
his/ her score is increased by as many marks as is the question number s/he answered correctly. If s/he
gives an incorrect answer, the score is deducted by 20% of the question number (negative marking).
Finally the score displays ‘IN’ if score is 10 or above, ‘OUT’ otherwise.
4. The file /etc/passwd contains information about all the users. Write a shell script which would
receive the logname during execution, obtain information about it from /etc/passwd and display this
information on the screen in an easily understandable format.

5. A shell can receive an argument ‘GOOD MORNING’, ‘GOOD AFTERNOON’ OR ‘GOOD


EVENING’. Write a shell script that displays the argument received in bold or in reverse video or as
blinking as per choice exercised by the user. If argument received is other than this, it reports ‘is not a
valid argument’
6. Write a shell script that receives any number of filenames as arguments. It should then check
whether a supplied argument is a file or a directory. If it is a directory, the script should report
accordingly and if it is a file, the name and the number of lines.

7. Write a shell script that checks whether the user has write permission to a specified file. If yes,
prompt the user to type a message which then gets appended to the file.
8. Write a shell script that stores names and phone numbers of customers and displays menu options
to add more records and search by customer name.
9. Write a shell script contacts.sh that places copies of contacts to contacts.bk and if copy operation is
successful, it displays contents of backup file else it reports file not found.

10. Write a shell script that offers a menu based program for performing addition, subtraction,
multiplication, division, modulo and exponentiation based arithmetic operations.
11. A class has given three tests of 50marks each. Sum of two best two tests was taken as
aggregate(agg) award of a letter grade as per the following criterion:
1) Grade A for agg >=75
2) Grade B for 60 <= agg <753) Grade C for 50 <= agg <60
4) Grade F otherwise.
Write a shell script which when given the roll no., the three test marks via command line arguments
displays the roll no., three test scores, sum of best two and letter grade.
Filters

Filters are programs that take plain text(either stored in a file or produced by another program) as standard
input, transforms it into a meaningful format, and then returns it as standard output. Linux has a number of
filters.
Some of the most commonly used filters are explained below:

1. cat: Displays the text of the file line by line.

2. head: Displays the first n lines of the specified text files. If the number of lines is not specified then by
default prints first 10 lines.
Syntax: head [-number_of_lines_to_print] [path]

3. tail :It works the same way as head, just in reverse order. The only difference in tail is, it returns the lines
from bottom to up.
Syntax: tail [-number_of_lines_to_print] [path]
4. sort: Sorts the lines alphabetically by default but there are many options available to modify the sorting
mechanism. Be sure to check out the man page to see everything it can do.

5. uniq: Removes duplicate lines. uniq has a limitation that it can only remove continuous duplicate
lines(although this can be fixed by the use of piping). Assuming we have the following data.
We can see that applying uniq doesn’t remove any duplicate lines, because uniq only removes duplicate lines
which are together.
When applying uniq to sorted data, it removes the duplicate lines because, after sorting data, duplicate lines
come together.

6. wc: wc command gives the number of lines, words and characters in the data.
In above image the wc gives 4 outputs as:
•number of lines
•number of words
•number of characters
•path

7. grep: grep is used to search a particular information from a text file.


Below are the two ways in which we can implement grep.

8. tac: tac is just the reverse of cat and it works the same way, i.e., instead of printing from lines 1 through
n, it prints lines n through 1. It is just reverse of cat command.

9. sed: sed stands for stream editor. It allows us to apply search and replace operation on our data
effectively. sed is quite an advanced filter and all its options can be seen on its man page.
The expression we have used above is very basic and is of the form ‘s/search/replace/g’
10. nl: nl is used to number the lines of our text data.

It can clearly bee seen in the above image that the lines have been numbered.

You might also like