Assignment 04 Sol (1)
Assignment 04 Sol (1)
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:
Here:
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.
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:
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,
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: