Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

UNIX –

Miscelleneou
s Topics
SEM VI MBAT CS
Contents
•Standard I/O Library

•Daemon processes

•Disk usage commands


Standard I/O Library
• Written by Dennis Ritchie in 1975

• When we open or create a file with the standard I/O library, we say that we have
associated a stream with the file. ( This stream is different than the XSI STREAMS)
•Three streams are predefined and automatically available to a process: standard input,
standard output, and standard error. These streams refer to the same files as the file
descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO, respectively.
•These three standard I/O streams are referenced through the predefined file pointers
stdin, stdout, and stderr. The file pointers are defined in the <stdio.h> header.
Standard I/O Library (Contd.)
•Standard I/O library allows buffering.
◦ Fully Buffered : Associated functions malloc and flush. Actual I/O takes place when the standard
I/O buffer is filled. Files residing on disk are normally fully buffered by the standard I/O library.
• Line Buffered. The buffer size is fixed. the standard I/O library performs I/O when a newline
character is encountered on input or output. This allows us to output a single character at a time
(with the standard I/O fputc function), knowing that actual I/O will take place only when we finish
writing each line. Line buffering is typically used on a stream when it refers to a terminal—standard
input and standard output, for example.
• Unbuffered. The standard I/O library does not buffer the characters. If we write 15 characters with
the standard I/O fputs function, for example, we expect these 15 characters to be output as soon as
possible. The standard error stream, for example, is normally unbuffered so that any error
messages are displayed as quickly as possible, regardless of whether they contain a newline.
Standard I/O Library (Contd.)
• The fopen, freopen, and fdopen functions open a standard I/O stream.
Standard I/O Library (Contd.)

fclose closes the stream


Standard I/O Library (Contd.)
Reading and writing a stream, three types of unformatted I/O:

1. Character-at-a-time I/O. We can read or write one character at a time, with the standard I/O functions
handling all the buffering, if the stream is buffered.

2. Line-at-a-time I/O. If we want to read or write a line at a time, we use fgets and fputs. Each line is
terminated with a newline character, and we have to specify the maximum line length that we can handle
when we call fgets.

3. Direct I/O. This type of I/O is supported by the fread and fwrite functions. For each I/O operation, we
read or write some number of objects, where each object is of a specified size. These two functions are often
used for binary files where we read or write a structure with each operation.
Standard I/O Library (Contd.)
Positioning a stream
Standard I/O Library (Contd.)
Formatted I/O.

Formatted output is handled by the five printf functions


Standard I/O Library (Contd.)
Formatted I/O.
Daemon processes
•Processes that live long
•Start at bootup and terminate at shut-down
•Run in the background
•Do not have a access terminal
•Types – System processes (OS specific), Kernel processes
(run forever for all)
Some daemon processes
init – kernel level, starts at bootstrap, starting system services specific to various run levels

kswapd daemon supports the virtual memory subsystem by writing dirty pages to disk slowly over time, so the pages can
be reclaimed.

flush daemon flushes dirty pages to disk when available memory reaches a configured minimum threshold. It also flushes
dirty pages back to disk at regular intervals to decrease data loss in the event of a system failure.

The rpcbind daemon provides the service of mapping RPC (Remote Procedure Call) program numbers to network port
numbers.

The rsyslogd daemon is available to any program to log system messages for an administrator.
inetd daemon listens on the system’s network interfaces for incoming requests for various
network servers.

The nfsd, nfsiod, lockd, rpciod, rpc.idmapd, rpc.statd, and rpc.mountd daemons provide support
for the Network File System (NFS).

The cron daemon executes commands at regularly scheduled dates and times.
Disk Utility
Checking Hard Disk Usage
To maintain adequate hard disk free space, these
strategies are used:
◦ Be vigilant against running dangerously low on
free space by using the df command
◦ Watch for conspicuous consumption using the
du command
◦ Follow a routine schedule for “garbage”
collection and removal by using the find and rm
commands

GUIDE TO UNIX USING LINUX, THIRD EDITION 15


Using the df (disk free) Utility
The df utility
reports on the
status of
1024-byte blocks
that are allocated,
used, and
available and the
mount point
-h human readable form
-m sizes in megabytes

GUIDE TO UNIX USING LINUX, THIRD EDITION 16


Using the du (disk usage) Utility

The du utility
summarizes disk
usage, expressed in
512-byte blocks
(default) or by the
number of bytes
(-b option)

-a displays info for files/dirs


-c creates an ending total
-b displays in bytes
GUIDE TO UNIX USING LINUX, THIRD EDITION 17
Removing Garbage Files
Garbage files are temporary files that lose their usefulness after several
days
Two examples of garbage files are core files (named core) and a.out files
Use the find command to assist you in locating these files and the rm
command to remove them.
◦ In the following slide, find is used to remove garbage files. The
–exec rm {} \; option tells Linux to rm all files found {} by the find
command.

GUIDE TO UNIX USING LINUX, THIRD EDITION 18


Removing Garbage Files (continued)

GUIDE TO UNIX USING LINUX, THIRD EDITION 19

You might also like