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

Assignment 04 Sol (1)

Assignment

Uploaded by

abisab007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Assignment 04 Sol (1)

Assignment

Uploaded by

abisab007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

ASSIGNMENT 4

1. Archive the contents of your home directory using tar. Compress the tar file with gzip.
Now uncompress and unarchive the .tar.gz file using cat, tar and gzip on one command line.
Ans 1 :
2. Use find to compile a list of all directories in the system, redirecting the output so that the
list of directories ends up in a file called directories.txt and the list of error messages ends up in a
file called errors.txt.
Ans 2:

find / -type d -printf '%f\n' 1 > directories.txt 2 > errors.txt

Here:

find /proc -type d 2> errors.txt | tee directories.txt

find /proc -type d 2> errors.txt > directories.txt


3. Try the command sleep 5. What does this command do?
Ans 3
sleep command is used to create a dummy job. A dummy job helps in delaying the execution.
It takes time in seconds by default but a small suffix(s, m, h, d) can be added at the end to
convert it into any other format. This command pauses the execution for an amount of time
which is defined by NUMBER.

The sleep command suspends the calling process of the next command for a specified amount
of time. This property is useful when the following command's execution depends on the
successful completion of a previous command.

4. Run the command in the background using &.

Ans 4

5. Run sleep 15 in the foreground, suspend it with Ctrlz and then put it into the background
with bg. Type jobs. Type ps. Bring the job back into the foreground with fg.

Ans 5:
6. Run sleep 15 in the background using &, and then use kill to terminate the process by its job
number. Repeat, except this time kill the process by specifying its PID.

Ans 6:

7. Run sleep 15 in the background using &, and then use kill to suspend the process. Use bg to
continue running the process.

Ans 7:
8. Startup a number of sleep 60 processes in the background, and terminate them all at the same
time using the pkill command.

Ans 8:
9. Use ps, w and top to show all processes that are executing.

Ans 9:

10. Use ps aeH to display the process hierarchy. Look for the init process. See if you can identify
important system daemons. Can you also identify your shell and its subprocesses?

Ans 10:
11. Combine ps fae with grep to show all processes that you are executing, with the exception of
the ps fae and grep commands.

Ans 11:
12. Start a sleep 300 process running in the background. Log off the server, and log back in
again. List all the processes that you are running. What happened to your sleep process? Now
repeat, except this time start by running nohup sleep 300.

Sol:

Every command in Linux starts a process at the time of its execution, which
automatically gets terminated upon exiting the terminal. Suppose, you are executing programs
over SSH and if the connection drops, the session will be terminated, all the executed
processes will stop, and you may face a huge accidental crisis. In such cases, running
commands in the background can be very helpful to the user and this is where nohup
command comes into the picture. nohup (No Hang Up) is a command in Linux systems that
runs the process even after logging out from the shell/terminal.
Usually, every process in Linux systems is sent a SIGHUP (Signal Hang UP) which is
responsible for terminating the process after closing/exiting the terminal. Nohup command
prevents the process from receiving this signal upon closing or exiting the terminal/shell. Once
a job is started or executed using the nohup command, stdin will not be available to the user
and nohup.out file is used as the default file for stdout and stderr. If the output of the nohup
command is redirected to some other file, nohup.out file is not generated.

Syntax:

nohup command [command-argument ...]


13. Multiple jobs can be issued from the same command line using the operators ;, && and ||.
Try combining the commands cat nonexistent and echo hello using each of these operators. Reverse
the order of the commands and try again. What are the rules about when the commands will be
executed?

Ans 13:

14. What does the xargs command do? Can you combine it with find and grep to find yet
another way of searching all files in the /home subdirectory tree for the word hello?

Ans 14:

The xargs command is used in a Linux to convert input from standard input into arguments to be a
commands.

In other words, through the use of xargs the output of a commands is used as the input of
another commands.

Syntax,

command1 | xargs command2

xargs -p rm

-p using this option will make zargs print a confirmation prompt with the action it's going to take.
15. What does the cut command do? Can you use it together with w to produce a list of login
names and CPU times corresponding to each active process? Can you now (all on the same
command line) use sort and head or tail to find the user whose process is using the most CPU?

Ans 15:

You might also like