GROUP A: ASSIGNMENTS

snottysurfsideServers

Dec 9, 2013 (3 years and 8 months ago)

705 views

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>













GROUP A: ASSIGNMENTS

(All Mandatory)





















Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Assignment No:

1


Title:

Implementation of Create/ rename/ delete a file using Unix/Linux commands.


Aim:
Implementation of Create/ rename/ delete a file using Unix/Linux commands.



Objectives:

1.
To learn and understand Commands.


Theory:

1.<Pwd.h>:


1) TOUCH:

At the terminal write the following:


[user1@com]$ touch filename [with extension]



2)

CAT
:


At the

terminal write the following:

$ cat > foo.txt

To display file contents, type

$ cat foot.txt


3)

MV:


At the terminal write the following:


[user1@com]$
mv foo.txt soo.txt






4)

RM:


At the terminal write the following:

[user1@com]$ rm soo.txt


Compilation /Running and Debugging the Solution:

The code written above will display the following output. For the first command CAT the output
is like this:


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>






Testing the Solution:

1.

All the commands will display the output based on it and the options
given to that
command.

2.

If we are giving a command and the option to that command then that option must be of
that command only otherwise will display the error.


Conclusion:

Should be written by students that what
they understand by the command
.


FAQ:

Q.1 Explain
need of commands.

Q.
2 Which command is used to create files
.

Q.3
Difference Between files created by touch command and cat command.

Q.4
Explain mv command
.

Q.5 Explain various options used with rm command.



NAME OF FACULTY:

SIGNATURE:

DATE:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Assignment No:

2


Title:

Write a function to display the list of devices connected to your system including the
physical names and its instance number. Write a function using mount and unmount command to

Mount device and un
-
mount it.


Aim:
Write a function

to display the list of devices connected to your system including the
physical names and its instance number. Write a function using mount and unmount command to

Mount device and un
-
mount it.



Objectives:

1.

To

learn and understand Commands.


Theory:

1.

ls

Command:

The
ls

command lists all files in the directory that match the
name
. If
name is left blank, it will list all of the files in the directory.

The syntax for the
ls

command is:

ls [options] [names]

Options:

Option

Description

-
a

Displays all files.

-
b

Displays nonprinting characters in octal.

-
c

Displays files by file timestamp.

-
C

Displays files in a columnar format (default)

-
d

Displays only directories.

-
f

Interprets each
name

as a directory, not a file.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



-
F

Flags filenames.

-
g

Displays the

long format listing, but exclude the owner name.

-
i

Displays the inode for each file.

-
l

Displays the long format listing.

-
L

Displays the file or directory referenced by a symbolic link.

-
m

Displays the names as a comma
-
separated list.

-
n

Displays t
he long format listing, with GID and UID numbers.

-
o

Displays the long format listing, but excludes group name.

-
p

Displays directories with
/

-
q

Displays all nonprinting characters as
?

-
r

Displays files in reverse order.

-
R

Displays subdirectories
as well.

-
t

Displays newest files first. (based on timestamp)

-
u

Displays files by the file access time.

-
x

Displays files as rows across the screen.

-
1

Displays each entry on a line.

Examples
:

ls
-
l

In the above example this command would list each
of the files in the current directory and the
files permissions, the size of the file, date of the last modification, and the file name or directory.
Below is additional information about each of the fields this command lists.

Permissions

Directories

Group

Size

Date

Directory or file

drwx
------

2

users

4096

Nov 2 19:51

mail/

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



drwxr
-
s
---

35

www

32768

Jan 20 22:39

public_html/

-
rw
-------

1

users

3

Nov 25 02:58

test.txt

Below is a brief description of each of the above categories shown when using the ls
-
l

command.

Permissions
-

The permissions of the directory or file.

Directories
-

The amount of links or directories within the directory. The default amount of
directories is going to always be 2 because of the . and .. directories.

Group
-

The group assign
ed to the file or directory

Size
-

Size of the file or directory.

Date
-

Date of last modification.

Directory of file
-

The name of the file or file.

Syntax

mount [
-
p |
-
v ]

mount

[
-
F FSType ] [ generic_options ] [
-
o specific_options ] [
-
O ] special | mount_point

mount [
-
F FSType ] [ generic_options ] [
-
o specific_options ] [
-
O ] special mount_point

mount
-
a [
-
F FSType ] [
-
V ] [ current_options ] [
-
o specific_options ] [ moun
t_point ... ]

-
p

Print the list of mounted file systems in the /etc/vfstab format. Must be the only option
specified.

-
v

Print the list of mounted file systems in verbose format. Must be the only option specified.

-
F

Used to specify the
FSType

on which to operate. The
FSType

must be specified or must be
determin able from /etc/vfstab, or by consulting /etc/default/fs or /etc/dfs
/fsTypes.

-
m

Mount the file system without making an entry in /etc/mnttab.

-
r

Mount the file system read
-
only.

-
o

Specify
FSType
-
specific options in a comma separated (without spaces) list of suboptions
and keyword
-
attribute pairs for interpretation by the
FSType
-
specific module of the
Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



command.

-
O

Overlay mount. Allow

the file system to be mounted over an existing mount point, making
the underlying file system inaccessible. If a mount is attempted on a pre
-
existing mount
point without setting this flag, the mount will fail, producing the error "device busy".

-
a

Perfor
m mount or umount operations in parallel, when possible.



If mount points are not specified, mount will mount all file systems whose /etc/vfstab
"mount at boot" field is "yes". If mount points are specified, then /etc/vfstab "mount at boot"
field will be
ignored.

If mount points are specified, umount will only umount those mount points. If none is
specified, then umount will attempt to umount all filesystems in /etc/mnttab, with the
exception of certain system required file systems: /, /usr, /var, /proc, /
dev/fd, and /tmp.

-
V

Echo the complete command line, but do not execute the command. umount generates a
command line by using the options and arguments provided by the user and adding to them
information derived from /etc/mnttab. This option should be use
d to verify and validate the
command line.

umount [
-
hV]

umount
-
a [
-
dflnrv] [
-
t vfstype] [
-
O options]

umount [
-
dflnrv] {dir|device}...

The umount command detaches the file system(s) mentioned from the file hierarchy. A file
system is specified by giving
the directory where it has been mounted. Giving the special device
on which the file system lives may also work, but is obsolete, mainly because it will fail in case
this device was mounted on more than one directory.

Note that a file system cannot be unmo
unted when it is `busy'
-

for example, when there are open
files on it, or when some process has its working directory there, or when a swap file on it is in
use. The offending process could even be umount itself
-

it opens libc, and libc in its turn may
o
pen for example locale files. A lazy unmount avoids this problem.

-
V

Print version and exit.

-
h

Print help message and exit.

-
v

Verbose mode.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



-
n

Unmount without writing in /etc/mtab.

-
r

In case unmounting fails, try to remount read
-
only.

-
d

In case th
e unmounted device was a loop device, also free this loop device.

-
i

Don't call the /sbin/umount.<filesystem> helper even if it exists. By default
/sbin/umount.<filesystem> helper is called if one exists.

-
a

All of the file systems described in /etc/mtab are unmounted. (With umount
version 2.7 and later: the proc filesystem is not unmounted.)

-
t vfstype

Indicate that the actions should only be taken on file systems of the specified type.
More than one type ma
y be specified in a comma separated list. The list of file
system types can be prefixed with no to specify the file system types on which no
action should be taken.

-
O options

Indicate that the actions should only be taken on file systems with the specifi
ed
options in /etc/fstab. More than one option type may be specified in a comma
separated list. Each option can be prefixed with no to specify options for which no
action should be taken.

-
f

Force unmount (in case of an unreachable NFS system). (Requires
kernel 2.1.116
or later.)

-
l

Lazy unmount. Detach the filesystem from the filesystem hierarchy now, and
cleanup all references to the filesystem as soon as it is not busy anymore.
(Requires kernel 2.4.11 or later.)

--
no
-
canonicalize

Don't canonicalize pa
ths. For more details about this option see the
mount

documentation.

The Loop Device

The umount command will free the loop device (if any) associated with the mount, in case it
finds the
option `loop=...' in /etc/mtab, or when the
-
d option was given. Any pend

ing loop
devices can be freed using `losetup
-
d'.

Notes

The syntax of external umount helpers is:

/sbin/umount.<suffix> {dir|device} [
-
nlfvr] [
-
t type.subtype]

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



where the <suffix> is

filesystem type or a value from "uhelper=" or "helper=" mtab option. The
-
t option is used for filesystems with subtypes support (for example, /sbin/mount.fuse
-
t
fuse.sshfs).

The uhelper= (unprivileged umount helper) is possible to use when non
-
root use
r wants to
umount a mountpoint which is not defined in the /etc/fstab file (e.g devices mounted by udisk).

The helper= mount option redirects all umount requests to the /sbin/umount. inde

pendently on
UID.

Examples:

1.mount /dev/usr /usr

Mount a local d
isk

2.mount
-
F dos /dev/rdsk/fds0d2.3.5 /floppy

Mount a MS
-
DOS floppy

3.mount
-
F hfs /dev/rdsk/fds0d3.3.5hi /floppy

Mount a Macintosh HFS floppy

4.mount
-
F hfs /dev/rdsk/dks0d7vol /cdrom

Mount a HFS CD
-
ROM

5.mount
-
F iso9660 /dev/rdsk/dks0d7vol /cdrom

Moun
t an ISO 9660 CD
-
ROM

6.umount /dev/fd0

Unmount floppy

7.umount /mnt

If /mnt is not busy, un
-
mount it.

8.umount
-
f /mnt

Force an unmount of /mnt, even if it is busy.


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Conclusion:

Should be written by students that what
they understand by the commands
.


FAQ:

Q.1 Explain need of commands.





















NAME OF FACULTY:

SIGNATURE:

DATE:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Assignment No:

3


Title:

Adding users and access rights in Linux.


Aim:
Adding users and access rights in Linux.



Objectives:

1. To

learn and understand Commands.

2. Student

should be able to create account and delete account.


Theory:

1.

useradd
:

Create a new user or update default new user information

2.

usermod
:

Modify a user account

3.

userdel
:
Delete a user account and related files

4.

passwd

:

Change the passw
ord on your current account. If you are root, you can change the password
for any user using:
passwd
username


5.

chmod perm filename


(=change mode) Change the file access permission for the files you own (unless you are root
in which case you can change any

file). You can make a file accessible in three modes: read
(r), write (w), execute (x) to three classes of users: owner (u), members of the group which
owns the file (g), others on the system (o). for example:

Linux add a new user called rakhi

Type the co
mmand as follows:

useradd rakhi

Set a password for rakhi:

passwd rakhi

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>





Without password user account will be in locked status. To unlock the account, you need to
use above passwd command. Use passwd command to assign a password and set password aging
gu
idelines.

Set accounts disable date

You can set date for the account to be disabled in the format YYYY
-
MM
-
DD with
-
e option
while creating account itself:

useradd
-
e {
yyyy
-
mm
-
dd
} {username}

useradd
-
e 2008
-
12
-
31 jerry

Set default password expiry

The
-
f {da
ys} option set number of days after the password expires until the account is disabled.
(If 0 is specified, the account is disabled immediately after the password expires. If
-
1 is
specified, the account is not be disabled after the password expires.)

user
add
-
f {
days
} {username}

useradd
-
e 2009
-
12
-
31
-
f 30 jerry


3.4

Testing the Solution:

1. All the commands will display the output based on it and the options given to that
command.

2. If we are giving a command and the option to that command then that option

must be
of that command only otherwise will display the error.


Conclusion:

Should be written by students that what they understand by the program.


FAQ:

Q.1 Explain need of commands.

Q.2 Which command is used to create user.

Q.3 Which

command is used to delete user.


NAME OF FACULTY:

SIGNATURE:

DATE:


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Assignment No:

4


Title:

Implement the commands for creation and deletion of directory. Write a program to
change current working directory and display the node details for each file in the new directory.


Aim:
Implement the commands for creation and deletion of directory. Write
a program to
change current working directory and display the node details for each file in the new directory.



Objectives:

1. To

learn and understand Commands.

2. Student

should be able to create and delete directories.


Theory:

1. MKDIR:

At the
terminal write the following:


[user1@com]$
mkdir A



2.

MV:


At the terminal write the following:


[user1@com]$
mv A B











3.RM:


At the terminal write the following:

[user1@com]$ rmdir B




Compilation /Running and Debugging the Solution:


The code written above will display the following output. For the first command Mkdir
the output is like this:



WHEN WE NEED TO SEE COMPLETE DISCRIPTION OF COMMAND THEN WE
DO AS;


[user1@com]$ mkdir
--
help



Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



SYNTAX


mkdir

[
OPTION
]
DIRECTORY
...



DESCRIPTION


Create the DIRECTORY(ies), if they do not already exist.



Mandatory arguments to long options are mandatory for short options


too.



-
m
,
--
mode
=
MODE


set permission mode (as in chmod), not rwxrwxrwx

-

umask



-
p
,
--
parents


no error if existing, make parent directories as needed



-
v
,
--
verbose


print a message for each created directory



-
Z
,
--
context
=
CONTEXT

(SELinux) set security context to CONTEXT



--
help

display this help and exit



--
version


output version information and exit



Testing the Solution:

1. All the commands will display the output based on it and the options given to that
command.

2. If we are giving a command and the option to that command then that option must be
of that command only otherwise will display the error.


Conclusion:

Should be written by students that what they understand by the commands.


FAQ:

Q.1 Explain need of
commands.

Q.2 Which command is used to create directory abc/a/b/c.

Q.3 Which command is used to delete directory abc/a/b/c.


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



NAME OF FACULTY:

SIGNATURE:

DATE:




























Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Assignment No:

5


Title:

Process related commands list the processes for the current shell, Display information
about processes, Display the global priority of a process, change the priority of a process with

default arguments.


Aim:
Process related commands list the processes for the current shell, Display information
about processes, Display the global priority of a process, change the priority of a process with

Default arguments.



Objectives:

1.To learn and understand Commands.


Th
eory:

1. TOP:

At the terminal write the following:


[user1@com]$ top



2. RENICE:



At the terminal write the following:

$ renice newpriority processid


3.

KILL:


At the terminal write the following:


[user1@com]$
kill
-
9 processid




Compilation /Running and Debugging the Solution:


The code written above will display the following output. For the first command TOP

Testing the Solution:

1. All the commands will display the output based on it and the options given to that
command.

2. If we are giving a command and the option to that command then that option must be
of that command only otherwise will display the error.





Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>








Conclusion:

Should be written by students that what they understand by the commands.


FAQ:

Q.1 Explain

need of commands.







NAME OF FACULTY:

SIGNATURE:

DATE:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Assignment No:

6


Title:

A) Use Operating system Commands to obtain the following results

1. To print the name of operating system

2. To print the login name

3. To print the host name



Aim:
A)
Use Operating system Commands to obtain the following results

1. To print the name of operating system

2. To print the login name

3. To print the host name



Objectives:

1.To learn and understand Commands.


Theory:

1. UNAME:

At the terminal write the
following:


[user1@com]$ uname

[user1@com]$Linux






2.

LOGNAME
:


At the terminal write the following:

[user1@com]$logname

[user1@com]$root


3.

WHO:


At the terminal write the following:


[user1@com]$
who

[user1@com]$


USER TTY FROM
LOGIN@ IDLE JCPU PCPU WHAT


root pts/0 10.22.32 20:47 0.00s 0.01s 0.00s w











Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



2.

HOSTNAME


At the terminal write the following:


[user1@com]$
hostname

[user1@com]$localhost@localdomain


Compilation /Running and Debugging the Solution:


The code written above will display the following output. For the first command
UNAME, LOGNAME/WHO, & HOSTNAME the output is like this:




WHEN WE NEED TO SEE COMPLETE DISCRIPTION OF COMMAND THEN WE
DO AS;


[user1@com]$ uname
--
help


DESCRIPTION


Print certain system information. With no OPTION, same as
-
s
.



-
a
,
--
all


print all information, in the following order, except omit
-
p


and
-
i

if unknown:



-
s
,

--
kernel
-
name


print the kernel name



-
n
,
--
nodename


print the network node hostname



-
r
,
--
kernel
-
release


print the kernel release



-
v
,
--
kernel
-
version


print the kernel version



-
m
,
--
machine


print the machine hardware name



-
p
,
--
processor


print the processor type or "unknown"



-
i
,
--
hardware
-
platform


print the hardware platform or "unknown"



-
o
,
--
operating
-
system


print the operating system



--
help

display this help and exit

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>





--
version


output version information and exit



Testing the Solution:

1. All the commands will display the output based on it and th
e options given to that
command.

2. If we are giving a command and the option to that command then that option must be
of that command only otherwise will display the error.



Conclusion:

Should be written by students that what they understand by the
commands.


FAQ:

Q.1 Explain need of commands.






















NAME OF FACULTY:

SIGNATURE:

DATE:



Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>
























GROUP B: ASSIGNMENTS

(At least six)


















Assignment

N
o:

1


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Title:

C/C++ script to display all logged in users.

Aim:
To
write C/C++ script to display all logged in users.



Objectives:

1)

To learn and understand Shells, Scripts, File System.

2)

Students should
be able to display all logged in users
.

3)

Students should know about types of users.

Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code for display all logged in users.

4.

Display all logged in users.

5.

Stop

T
heory:


1.
<Pwd.h>:


NAME


pwd.h
-

password structure


SYNOPSIS


#include <pwd.h>


DESCRIPTION


The <pwd.h> header shall provide a definition for struct
passwd, which


shall include at least the following members:




char *pw_name


User's login name.



uid_t pw_uid


Numerical user ID.



gid_t pw_gid


Numerical group ID.



char *pw_dir


Initial working directory.




char *pw_shell Program to use as shell.



The gid_t and
uid_t types shall be defined as

described in <sys/types.h> .


2.<stdio.h>:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Input and Output operations can also be performed in C++ using the

C

St
andar
d

I
nput
and

O
utput Library
(
cstdio
, known as

stdio.h

in the C language). This library uses what are
called

streams

to operate with physical devices such as keyboards, printers, terminals or with any
other type of files supported by the system. Streams are an abstraction to interact
with these in an
uniform way; All streams have similar properties independently of the individual characteristics
of the physical media they are associated with.

Streams are handled in the

cstdio

library as pointers to

FILE

objects. A pointer to a

FILE

object
uniquely identifies a stream, and is used as a parameter in the ope
rations involving that stream.

There also exist three standard streams:

stdin
,

stdout

and

stderr
, which are automatically created
and opened for all programs using the library.


NAME

stdi
o.h
-

standard buffered input/output


SYNOPSIS

#include <stdio.h>


DESCRIPTION

The

<stdio.h>

header defines
macro names as positive integral constant expressions

3.<unistd.h>:

NAME

unistd.h
-

standard symbolic constants and types

SYNOPSIS

#include <
unistd.h>

DESCRIPTION

The

<unistd.h>

header defines miscellaneous symbolic constants and types, and declares
miscellaneous functions. The actual values of the constants are unspecified except
.

4.<sys/types.h>:

NAME

sys/types.h
-

data types

SYNOPSIS

#include <sys/types.h>

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



DESCRIPTION

The

<sys/types.h>

header shall include definitions for at least the following types:

dev_t
:

Used for device IDs.

gid_t
:

Used for group IDs.

id_t
:


Used as a general identifier; can be used to contain at least a

pid_t
,

uid_t
, or

gid_t
.


ino_t
:

Used for file serial numbers.

mode_t
:

Used for some file attributes.

nlink_t
:

Used for link counts.

off_t
:

Used for file sizes.

pid_t
:

Used for process IDs and process group IDs.

5.struct paaswd:

It is a
data structure containing
user account information
.



SYNOPSIS

#include <pwd.h>

struct passwd {


char *pw_name;


char *pw_passwd;


uid_t pw_uid;


gid_t pw_gid;


time_t pw_change;


char *pw_class;


char *pw_gecos;


char *pw_dir;


char *pw_shell;


time_t pw_expire;

};


DESCRIPTION

The

passwd

structure

is returned by
the

getpwnam()

getpwnam_r()
,

getpwuid()

and

getpwuid_r()

functions. It provides information
about a user account. The structure has the following field
s:

pw_name
:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



User's login name.

pw_passwd
:



Encrypted password. This field is not supported.

pw_uid
:


User ID.

pw_gid
:



Group ID.

pw_change
:



Password change time. This field is not supported.

pw_class
:


User access class. This field is not supported.

pw_gecos
:



User's full name.

pw_dir
:


User's login directory.

pw_shell
:


User's login shell.

pw_expire
:


Password expiration time.


Conclusion:


Should be written by students that what
they understand by the program.


FAQ:

Q.1 Explain need of vi editor.

Q.
2 Explain Types of users.

Q.3
what

are logged in users and how they are different from other users.

Q.4
which

type of data can be accessed by logged in users.



NAME OF FACULTY:

SIGNATURE:

DATE:

Program:

#include<pwd.h>

#include<stdio.h>

#include<
unistd.h>

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



#include<sys/types.h>

int main()

{

struct passwd *procuid;

procuid= getpwuid(getuid());

printf("
\
nReal name
--

%s",procuid
-
>pw_gecos);

printf("
\
nlogin name
--
%s",procuid
-
>pw_name);

printf("
\
nReal name
--
%s",procuid
-
>pw_dir);

printf("
\
nReal name
--
%s",procuid
-
>pw_shell);

printf("
\
nReal name
--
%lu",(unsigned long)getpwuid(getuid())
-
>pw_uid);

printf("
\
nReal name
--

%lu",(unsigned long)getpwuid(getuid())
-
>pw_gid);

return 0;

}


OR

#include<stdio.h>

int main()

{

system("who");

return 0;

}


OR

#include<stdio.h>

#include<sys/utname.h>

#include<utmp.h>

int main()

{

struct utmp *n;

char *a;

int i;

setutent();

n=getutent();

while(n!=NULL)

{

if(n
-
>ut_type==7)

{

printf("%
-
9s",n
-
>ut_user);

printf("%
-
12s",n
-
>ut_line);

a=ctime(n
-
>
ut_time);

printf("");

for(i=4;i<16;i++)

printf("%c",a[i]);

printf("(");

printf("%s",n
-
>ut_host);

printf(")");

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



}

n=getutent();

}

return 0;


}



Steps:

1.

Type vi progname.c

2.

In vi editor press i to insert text into insert mode.

3.

Type program.

4.

Press
Esc.

5.

Press :wq to save and quit from vi.

6.

To compile gcc progname.c

7.

To execute ./a.out
















Assignment N
o
: 2


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Title:

C/C++ Program to display the list of devices connected to your system including the
physical names and its instance number.


Aim:
Write

C/C++ Program to display the list of devices connected to your system including
the physical names and its instance number.


Objective:

1.

To learn and understand Shells, Scripts, File System.

2.

Students should have knowledge about physical names and

instance number of devices.


Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code for display the list of devices connected to system including the physical
names and its instance no.

4.

Display the list of devices connected to system including the physical nam
es and its
instance no.

5.

Stop

Theory:

1.
The File system as a Universal Name Space
:

In UNIX, files are not only a stream of bytes with a consistent
API;

they can also be referenced
in a uniform manner: the file system is used as a universal namespace.

In modern UNIX operating systems all devices and most type of communications between
processes are managed and visible as files or pseudo
-
files within the file system hierarchy. This
fundamental UNIX vision and design principle, known as “Everything is a F
ile”, is one of the
key factors for UNIX success and longevity. It provided a powerful yet simple abstraction that
the system, the tools and the community could build on. More importantly it provided strong
Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



integration and a fundamental composition mechani
sm for connecting tools and applications in
an ad
-
hoc manner to solve the problem at hand.

2.
Lspci:


NAME

lspci
-

list all PCI devices

SYNOPSIS

lspci

[
options
]

DESCRIPTION

lspci

is a utility for displaying information about all PCI buses in the system and
all devices
connected to them.
By default, it shows a brief list of devices. Use the options described below to
request either a more verbose output or output intended for parsing by other programs.

If you are going to report bugs in PCI device drivers or i
n

lspci

itself, please include output of
"lspci
-
vvx" or even better "lspci
-
vvxxx" (however, see below for possible caveats).

Some parts of the output, especially in the highly verbose modes, is probably intelligible only to
experienced PCI hackers. For t
he exact definitions of the fields, please consult either the PCI
specifications or the

header.h

and

/usr/include/linux/pci.h

include files.

Access to some parts of the PCI configuration space is restricted to root on many operating
systems, so the
features of

lspci

available to normal users are limited. However,

lspci

tries its
best to display as much as available and mark all other information with

<access denied>

text.

OPTIONS

Tag

Description

-
v

Be verbose and display detailed information about
all devices.

-
vv

Be very verbose and display more details. This level includes
everything deemed useful.

-
vvv

Be even more verbose and display everything we are able to parse,
even if it doesn’t look interesting at all (e.g., undefined memory
牥g楯湳⤮
=
-
n

Show PCI vendor and device codes as numbers instead of looking
Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



them up in the PCI ID list.

-
x

Show hexadecimal dump of the standard part of the configuration
space (the first 64 bytes or 128 bytes for CardBus bridges).

-
xxx

Show hexadecimal dump of th
e whole PCI configuration space. It
is available only to root as several PCI devices

crash

when you try
to read some parts of the config space (this behavior probably
doesn’t violate the PCI standard, but it’s at least very stupid).
However, such devices a
re rare, so you needn’t worry much.

-
xxxx

Show hexadecimal dump of the extended (4096
-
byte) PCI
configuration space available on PCI
-
X 2.0 and PCI Express
buses.

-
b

Bus
-
centric view. Show all IRQ numbers and addresses as seen by
the cards on the PCI bus
instead of as seen by the kernel.

-
t

Show a tree
-
like diagram containing all buses, bridges, devices and
connections between them.

-
s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]]



Show only devices in the specified domain (in case your machine
has
several host bridges, they can either share a common bus
number space or each of them can address a PCI domain of its
own; domains are numbered from 0 to ffff), bus (0 to ff), slot (0 to
1f) and function (0 to 7). Each component of the device address
can b
e omitted or set to "*", both meaning "any value". All
numbers are hexadecimal. E.g., "0:" means all devices on bus 0,
"0" means all functions of device 0 on any bus, "0.3" selects third
function of device 0 on all buses and ".4" shows only the fourth
func
tion of each device.

-
d [<vendor>]:[<device>]



Show only devices with specified vendor and device ID. Both ID’s
are given in hexadecimal and may be omitted or given as "*", both
meaning "any value".

-
i <file>



Use

<file> as the PCI ID list instead of

/usr/share/hwdata/pci.ids.

-
m

Dump PCI device data in machine readable form (both normal and
verbose format supported) for easy parsing by scripts. Please don’t
Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



use any other formats for this purpose, they are likely to change in
the future versions of l
spci.

-
D

Always show PCI domain numbers. By default, lspci suppresses
them on machines which have only domain 0.

-
M

Invoke bus mapping mode which performs a thorough scan of all
PCI devices, including those behind misconfigured bridges etc.
This option
is available only to root and it gives meaningful results
only if combined with direct hardware access mode (otherwise the
results are identical to normal listing modes, modulo bugs in lspci).
Please note that the bus mapper doesn’t support PCI domains and

scans only domain 0.

--
version



Shows

lspci

version. This option should be used stand
-
alone.


3.
/proc/devices:


This file displays the various character and block devices currently configured (not including
devices whose modules are not loaded). Below

is a sample output from this file:

Character devices:


1 mem


4 /dev/vc/0


4 tty


4 ttyS


5 /dev/tty


5 /dev/console


5 /dev/ptmx


7 vcs


10 misc


13 input


29 fb


36 netlink


128 ptm


136 pts


180 usb




Block devices:


1 ramdisk


3 ide0


9 md


22 ide1

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




253 device
-
mapper


254 mdp

The output from

/proc/devices

includes the major number and name of the device, and is broken
into two major sections:

Character devices

and

Block devices
.

Character devices

are similar to

block devices
, except for two basic differences:

1.

Character devices do not require buffering. Block devices have a buffer available,
allowing them to order requests before addressing them. This is important for devices
desig
ned to store information


such as hard drives


because the ability to order the
information before writing it to the device allows it to be placed in a more efficient order.

2.

Character devices send data with no preconfigured size. Block devices can send a
nd
receive information in blocks of a size configured per device.


Conclusion:


Should be written by students that what they understand by the program..


FAQ:

Q.1 W
hy all devices connected in system is considered as a file in
UNIX

system.

Q.2 W
hat

do you mean by physical names of the devices.

Q.3 W
hat do you mean by instance no.

Q.4 Why

i
n UNIX everything is a considered as Stream of Bytes.

Q.5 W
hich types of operations we can perform on streams of bytes.







NAME OF FACULTY:

SIGNATURE:

DATE:

Program:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



#include<stdio.h>

int main()

{

printf("
\
n we are executing LSPCI using system");

system("lspci");

return 0;

}


OR

#include<stdio.h>

int main()

{

printf("
\
n we are executing info. using system");

system("cat /proc/devices");

return 0;

}



















Assignment N
o: 3

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Title:

C/C++ Program to Parent creating the child process by use of fork.


Aim:
Write a

C/C++ Program to Parent creating the child process by use of fork.


Objective:

1.

Students should have knowledge about process and sub
-
process.

2.

Students should have knowledge about fork and sub
-
fork.



Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code to creating the child process by use of fork.

4.

Display Details.

5.

Stop

Theory:


1. FORK:

Fork

creates a child process that differs from the parent process only in its PID and PPID, and in
the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.

Under Linux,
fork

is implemented using copy
-
on
-
write pages,
so the only penalty incurred by
fork is the time and memory required to duplicate the parent's page tables, and to create a unique
task structure for the child.

RETURN VALUE

On success, the PID of the child process is returned in the parent's thread of ex
ecution, and a 0 is
returned in the child's thread of execution. On failure, a
-
1 will be returned in the parent's
context, no child process will be created, and
errno

will be set appropriately.

ERRORS

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



EAGAIN


Fork

cannot allocate sufficient memory to copy the parent's page tables and allocate a
task structure for the child.

ENOMEM


Fork

failed to allocate the necessary kernel structures because memory is tight.

CONFORMING TO

The
fork

call conforms to SVr4, SVID,
POSIX, X/OPEN and BSD 4.3.

On success, the
fork

syscall returns twice: once in the (calling) parent process (where it gives the
pid

of the child process), and once in the newly created child process (where it gives 0).
Otherwise, the two process are clones (and some Linux implementations have a
fork

implemented above the Linux specific
clone (2)

syscall) and are executing the same program
with nearly the same state (actually two nearly identical copies). The two (parent and child)
processes are running simultaneously (as tasks scheduled by the kernel, pe
rhaps in parallel on
different processor cores).

The
fork (2)

syscall might (rarely) fail (e.g. to avoid
fork bombs
), e.g. when the
RLIMIT_NPROC

limit set with
setrlimit (2)

syscall has been reached. When it does fail, the
fork

syscall return
-
1 and you should check
errno
. It is good practice to check the failure of every
syscall
, and
fork

is not an exception.

Fork is the usual way to start processes, all [but some rare exceptions] the user processes are
started by some
fork

syscall (or a variant like
vfork (2)
, or
clone (2)
). In particular, when you
type a command (e.g.
ls

or
dat
e
) in a shell (e.g.
/bin/bash

perhaps running in a terminal
emulator), the shell is very often
fork
ing itself, then
execve
-
ing the required program (exceptions
are shell built
-
ins like
cd
).

You can call
fork

many times (a typical shell implementation does
that for every command,
except the built
-
in ones like
cd
; you might want to study the source code of free software shells
like
sash

or
bash
). You should eventually wait for the child processes using the
wait (2)

or
waitpid (2)

syscall. A process can change its executable file and address space with the
execve
(2)

syscall. Its
address space

can change using
mmap(2)

and related syscalls.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



You might want to use
strace
-
f

to understand what syscalls are made, e.
g. by some shell.

Conclusion :

Should be written by students that what they understand by the program..


FAQ:

Q.1
Explain Process and sub process.

Q.2 Explain need of fork.

Q.3 Difference between system call and fork.

Q.4
C
an shell c
reates a sub shell
using a fork?

















NAME OF FACULTY:

SIGNATURE:

DATE:


Program:

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



#include<stdio.h>


main()

{


int id;



printf("Before fork()
\
n");


id=fork();



if(id==0)


{


printf("Child has started: %d
\
n ",getpid());


printf("Parent of this child : %d
\
n",getppid());


printf("child prints 1 item :
\
n ");


sleep(10);


printf("child prints 2 item :
\
n");


}


else


{


printf("Parent has started: %d
\
n",getpid());


printf("Par
ent of the parent proc : %d
\
n",getppid());


}



printf("After fork()");

}













Assignment N
o: 4

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Title:

C/C++ program to assign nice values to processes and dynamically monitor them.


Aim:

Write

C/C++ program to assign nice values to
processes and dynamically monitor them.


Objective:

1.

Students should have knowledge about process

priorities and their need
.

2.

Students should have knowledge about

need of nice
.


Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code to assign nice values to proce
sses and dynamically monitor them.

4.

Display Details.

5.

Stop

Theory:

Nice
-

change process priority

Synopsis

#include <unistd.h>


int nice(int
inc
);


Description

nice
() adds
inc

to the nice value for the calling process. (A higher nice value means a low
priority.) Only the super

user may specify a negative increment, or priority increase. The range
for nice values is described in
getpriority
(2).

Return Value

On success, the new
nice value is returned (but see NOTES below). On error,
-
1 is returned, and
errno

is set appropriately.

Errors

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Tag

Description

EPERM


The calling process attempted to increase its priority by supplying a
negative
inc

but has insufficient privileges. Under Linux the
CAP_SYS_NICE

capability is required. (But see the discussion of the
RLIMIT_NICE

resource limit in
setrlimit
(2).)

Conforming To

SVr4, 4.3BSD, POSIX.1
-
2001. However, the Linux and (g)libc

(earlier than glibc 2.2.4) return
value is nonstandard, see below. SVr4 documents an additional EINVAL error code.

Notes

Nice value is the value that controls {increments or decrements
}

the priority of the process. This value that is returned by the nic
e () system call. The equation for
using nice value is:

Priority = (“recent CPU usage”/constant) + (base
-

priority) + (nice value)
.


Only the administrator can supply the nice value. The nice () system call works for the running
process only. Nice value
of one process cannot affect the nice value of the other process.
SUSv2
and POSIX.1
-
2001 specify that
nice
() should return the new nice value. However, the Linux
syscall and the
nice
() library function provided in older versions of (g)libc (earlier than gl
ibc
2.2.4) return 0 on success. The new nice value can be found using
get priority

(2).

Since glibc 2.2.4,
nice
() is implemented as a library function that calls
get priority
(2) to obtain
the new nice value to be returned to the caller. With this implementation, a successful call can
legitimately return
-
1. To reliably detect an error, set
errno

to 0 before the call, and check its
value when
nice

() returns
-
1.

Conclusion :

Should be written by students that what they understand by the program..


FAQ:

Q.1 what

are process priorities and their n
eed?

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Q
.2 Explain need of nice.
























NAME OF FACULTY:

SIGNATURE:

DATE:

Program:

#include<stdio.h>

int main()

{

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



system("ps
-
e");

system("top");

system("renice
-
9 136");

return 0;

}


























Assignment N
o: 5


Title:

C/C++ program to identify the available memory in the system.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Aim:

Write

C/C++ program to identify the available memory in the
system.


Objective:

1.

Students should know about memory, types of memory.

2.

Student should know about memory management in the system.


Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code to identify the available memory in the system.

4.

Display Details.

5.

Stop


Theory:

1.

/proc/meminfo:

/proc/meminfo is one of the more commonly used files in the /proc/, as it reports a large
amount of valuable information about the Linux system’s memory. Here is the brief
description of what each value stands for
:



MemTotal: Total
usable RAM in kilobytes (i.e. physical memory minus a few reserved
bytes and the kernel binary code)



MemFree: The amount of physical RAM left unused by the system.



Buffers: The amount of physical RAM used for file buffers.



Cached: The amount of physical RA
M used as cache memory. Memory in the pagecache
(diskcache) minus SwapCache.



SwapCache: This is the amount of Swap used as cache memory. Memory that once was
swapped out, is swapped back in, but is still in the swapfile.



Active: The total amount of buffer
or page cache memory, that is active. This part of the
memory is used recently and usually not reclaimed unless absolutely necessary.



Inactive: The total amount of buffer or page cache memory that are

free and available. This
is memory that has not been recently used and can be reclaimed for other purposes by the
paging algorithm.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>





HighTotal: is the total amount of memory in the high region. The HighTotal value can vary
based on the type of kernel used.

Kernel uses indirect tricks to access the high memory
region. Data cache can go in this memory region.



LowTotal: The total amount of non
-
highmem memory.



LowFree: The amount of free memory of the low memory region. This is the memory the
kernel can address

directly. All kernel datastructures need to go into low memory



SwapTotal: Total amount of physical swap memory.



SwapFree: Total amount of swap memory free.



Dirty: The total amount of memory waiting to be written back to the disk.



Writeback: The total amou
nt of memory actively being written back to the disk.



Committed_AS: An estimate of how much RAM you would need to make a 99.99%
guarantee that there never is OOM (out of memory) for this workload. Normally the kernel
will overcommit memory. This parameter
represents the worst case scenario value, and also
includes swap memory.

2.
/proc/cpuinfo:

/proc/cpuinfo

is a short, read
-
only,

plain text

file that
contains

information

about
the CPUs (central processing units) on a computer.It can easily be read with a command such
as

cat
, i.e.,
cat /proc/cpuinfo

If a computer contains two or more CPUs, the information about

each is separated by a blank
line. The information about each processor consists of a set of lines (18 on Red Hat 9), each of
which contains a key word followed by a separator (consisting of spaces, a colon and then
another space) and then by a value. Eac
h key word can be any combination of

alpha
numeric,
underscore and space

characters
.

Only a few of the lines contain information that is meaningful to
most users. Among them
are

processor

(the value of which is zero for single
-
processor systems),

vendor_id

(the value of
which is

GenuineIntel

in the case of an Intel processor),

cpu family,

model_name,

cpu
MHz

(processor speed in millions of cycles per sec
ond),

cache size

(the amount of high
speed

cache

memory

built into the processor) and

fpu

(the value of which is

yes

if the processor
contains a floating point unit).

The

flags

field shows which features are

available in the CPU; this information is of interest only
to users with an in
-
depth knowledge of processors. The final item,

bogomips, is a

Linux
-
specific
measurement of the CPU's speed in MIPS (millions

of instructions per second) while not
performing any actual work; it is not an accurate indicator of overall processor speed and is only
used for some testing purposes.

3.struct sysinfo:

Name:

sysinfo
-

returns information on overall system statistics

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Synopsis:

#include <
sys/sysinfo.h
>

int sysinfo(struct sysinfo *info);

Description:

Until Linux 2.3.16,

sysinfo() used to return information in the following structure:

struct sysinfo {


long

uptime; /* Seconds since boot */


unsigned long loads[3]; /* 1, 5, and 15 minute load averages */


unsigned long totalram; /* Total usable main memory size */


unsigned long freeram; /* Available memory size */


unsigned long s
haredram; /* Amount of shared memory */


unsigned long bufferram; /* Memory used by buffers */


unsigned long totalswap; /* Total swap space size */


unsigned long freeswap; /* swap space still available */


unsigned short procs; /* Number
of current processes */


char _f[22]; /* Pads structure to 64 bytes */

};

and the sizes were given in bytes.

Since Linux 2.3.23 (i386), 2.3.48 (all architectures) the structure is:

struct sysinfo {


long uptime; /* Seconds sin
ce boot */


unsigned long loads[3]; /* 1, 5, and 15 minute load averages */


unsigned long totalram; /* Total usable main memory size */


unsigned long freeram; /* Available memory size */


unsigned long sharedram; /* Amount of shared memor
y */


unsigned long bufferram; /* Memory used by buffers */


unsigned long totalswap; /* Total swap space size */


unsigned long freeswap; /* swap space still available */


unsigned short procs; /* Number of current processes */


unsigne
d long totalhigh; /* Total high memory size */


unsigned long freehigh; /* Available high memory size */


unsigned int mem_unit; /* Memory unit size in bytes */


char _f[20
-
2*sizeof(long)
-
sizeof(int)]; /* Padding to 64 bytes */

};

and

the sizes are given as multiples of

mem_unit

bytes.

sysinfo() provides a simple way of getting overall system statistics. This is more portable than
reading

/dev/kmem.

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Return Value:

On success, zero is returned. On error,
-
1 is returned, and

errno

is set
appropriately.

Errors:

EFAULT

pointer to

struct sysinfo

is invalid

Conforming To:

This function is Linux
-
specific, and should not be used in programs intended to be portable.

The Linux kernel has a

sysinfo() system call since 0.98.pl6. Linux libc contains
a

sysinfo()
routine since 5.3.5, and glibc has one since 1.90.


Conclusion :

Should be written by students that what they understand by the program..



FAQ:

Q.1 What is Memory?

Q.2 Explain Types of memory?

Q.3 How UNIX System performs memory management.

Q.4 What is minimum block size in Unix.

Q.5 How available memory can be displayed.





NAME OF FACULTY:

SIGNATURE:

DATE:

Program:

#include <stdio.h>

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



#include <sys/sysinfo.h>


int main(void)

{


struct sysinfo myinfo;


unsigned long total_bytes;



sysinfo(&myinfo);



total_bytes = myinfo.mem_unit * myinfo.totalram;




printf("total usable main memory is %lu B, %lu MB
\
n",


total_bytes, total_bytes/1024/1024);



return 0;


}


OR


#include<stdio.h>

int main()

{

system("cat /proc/me
minfo");

return 0;

}


OR


#include<stdio.h>

int main()

{

system("cat /proc/cpuinfo");

return 0;

}







Assignment N
o: 6


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



Title:

C/C++ Scripts required to start, stop and perform daily cleanup tasks.


Aim:

Write

C/C++ Scripts required to start, stop

and perform daily cleanup tasks
.


Objective:

1.

Students should know
about Clean up task


Algorithm:

1.

Start

2.

Enter in vi editor.

3.

Write a code to start, stop and perform daily cleanup tasks.

4.

Display Details.

5.

Stop


Theory:

Use this procedure as a consistent method of starting services on Unix. A side benefit of this
procedure is that it keeps user
-
space applications out of the system startup/shutdown process so
they do not hinder a system during boot or shutdown.

The system
directory tree "/usr/app/" exists to provide this startup/shutdown capability. Each
service will have its own subdirectory containing the scripts required to start, stop and perform
daily cleanup tasks. Services are registered in the file "/usr/app/service
s.node" so the system
knows which ones to start/stop.

Basic "cleanup" functionality is provided if you create a script "rc.cleanup"; this script will be
run daily at 4:15am. Typical uses include cleaning up log files and/or temporary files.

Do not install
other application
-
specific files in "/usr/app/." That directory should contain only
the three scripts for startup (rc.local), shutdown (rc.shutdown) and the optional cleanup script
(rc.cleanup).

NOTE:

As of 01/25/2007, services are shut down in reverse order of how they were started. This
means that "services.node" is parsed top to bottom to initiate startup and bottom to top to
perform shutdown. Cleanup is unaffected and will be processed in the order

the services appear
in the file, just like startup.

To use start up and shut down scripts

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



1.

Create subdirectory of /usr/app for your service:
sudo mkdir
/usr/app/SERVICENAME

2.

Create "etc" subdirectory to hold your scripts:
sudo mkdir
/usr/app/SERVICENAME/etc

3.

Create startup script "rc.local":
sudo vi /usr/app/SERVICENAME/etc/rc.local

4.

Create shutdown script "rc.shutdown":
sudo vi
/usr/app/SERVICENAME/etc/rc.shutdown

5.

OPTIONAL: Create daily cleanup script "rc.cleanup":

sudo vi /usr/app/SERVICENAME/etc/rc.cleanup

6.

Test your scripts manually to make sure they actually start, shut down, and clean up after
your application.

7.

Add the name of your directory to "services.node":
sudo vi /usr/app/services.node

The directory name is relative to "/usr/app/" and should not cont
ain slashes.

Continuing our example, add
SERVICENAME

to the file on a line by itself.


Conclusion :

Should be written by students that what
they understand by the program.


FAQ:

Q.1 Explain Clean up task.

Q.2 Explain need of clean up task.

Q.3 C
an system is able to perform
cleans

up task automatically.

Q.4 Explain main steps behind clean up tasks.







NAME OF FACULTY:

SIGNATURE:

DATE:

Program:

#include<stdio.h>

#include<sys/types.h>

#include<stdlib.h>

#include<signal.h>

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



#include<unistd.h>

#include<string.h>

int spawn(char *prog,char **avg_list)

{

pid_t child_id;

child_id=fork();

if(child_id!=0)

{

return child_id;

}

else

{

execvp(prog,avg_list);

fprintf(stderr,"any error occured");

abort();

}

}


int main()

{

char

*avg_list[]={"ls","
-
l","/","NULL"};

int ch,ans,child_id;

struct sigaction sigchild_act;

{

printf("Menu
\
n 1.Start
\
n 2.Stop
\
n 3.Cleanup");

printf("
\
n Enter ur choice");

scanf("%d",&ch);

switch (ch)

{

case 1:

child_id=spawn("ls",avg_list);

brea
k;

case 2:

kill(child_id,SIGTERM);

break;

case 3:

printf("
\
n Cleanup task");

exit(0);

break;

}

printf("
\
n Do you Want to continue");

scanf("%d",&ans);

}

while(ans==1);

return 0;

}


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




O/P

output:


gcc
-
o a execdemo.c

./a.out

Menu


1.Start



2.Stop


3.Cleanup


Enter ur choice1



Do you Want to continuels: cannot access NULL: No such file or directory

ls: cannot access : No such file or directory

/:

total 64

lrwxrwxrwx. 1 root root 7 Aug 18 19:22 bin
-
> usr/bin

dr
-
xr
-
xr
-
x
. 3 root root 4096 Aug 18 19:34 boot

drwxr
-
xr
-
x. 18 root root 3400 Sep 20 15:53 dev

drwxr
-
xr
-
x. 142 root root 12288 Sep 20 15:53 etc

drwxr
-
xr
-
x. 7 root root 4096 Aug 30 16:21 home

lrwxrwxrwx. 1 root root 7 Aug 18 19:22 lib
-
> usr/lib

lrw
xrwxrwx. 1 root root 9 Aug 18 19:22 lib64
-
> usr/lib64

drwx
------
. 2 root root 16384 Aug 18 19:17 lost+found

drwxr
-
xr
-
x. 2 root root 4096 Jul 19 2012 media

drwxr
-
xr
-
x. 2 root root 4096 Jul 19 2012 mnt

drwxr
-
xr
-
x. 2 root root 4096 Jul

19 2012 opt

dr
-
xr
-
xr
-
x. 179 root root 0 Sep 20 15:53 proc

dr
-
xr
-
x
---
. 5 root root 4096 Sep 20 16:32 root

drwxr
-
xr
-
x. 37 root root 1240 Sep 20 15:53 run

lrwxrwxrwx. 1 root root 8 Aug 18 19:22 sbin
-
> usr/sbin

drwxr
-
xr
-
x. 2 root root

4096 Jul 19 2012 srv

dr
-
xr
-
xr
-
x. 13 root root 0 Sep 20 15:53 sys

drwxrwxrwt. 13 root root 280 Sep 20 16:34 tmp

drwxr
-
xr
-
x. 13 root root 4096 Aug 18 19:22 usr

drwxr
-
xr
-
x. 20 root root 4096 Aug 18 19:32 var


^Z

[1]+ Stopped

./a

[student@localhost ~]$ ./a

Menu


1.Start


2.Stop


3.Cleanup


Enter ur choice2

Terminated

Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



[student@localhost ~]$ ./a

Menu


1.Start


2.Stop


3.Cleanup


Enter ur choice3




Cleanup task

*/





















Assignment
No: 7


Title:

Write Java script to display all logged in users. Count the number of logged
-
in users.
Write a program to create a foreground and background process for the selected user and display
its status.


Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>




Aim:

Write Java script to display all logged

in users. Count the number of logged
-
in users.
Write a program to create a foreground and background process for the selected user and display
its status.



Objective:

1. Students should know about logged in users.

2. Students should know about foreground

and background processes.


Algorithm:

1.
Start

2.
Enter in vi editor.

3.
Write a
Java script to display all logged in users
.

4.
Display Details.

5.
Stop


Theory:


To display all logged in users:
Refer Assignment 1.

Foreground and background process:

As a multitasking operating system, Linux allows you run multiple processes in the background
while you continue to work in the foreground.

Background Process

Unlike with a foreground process, the shell does not have to wait for a background process to
end before it can run more processes. Within the limit of the amount of memory available, you
can enter many background commands one after another. To run a command as a background
process, type the command and add a space and an ampersand to the end of th
e command. For
example:

$

command1 &

Immediately after entering the above command, the shell will execute the command. While that
is running in the background, the shell prompt (% for the C Shell, and $ for the Bourne Shell and
Operating System and Administration Lab Manual

Department of Computer Engg. DCOER, Pune


Submitted By: <Student Name> Roll No :< Student R. No.>



the Korn Shell) will return.

At this point, you can enter another command for either foreground
or background process. Background jobs are run at a lower priority to the foreground jobs.

You will see a message on the screen when a background process is finished running.

Foreground Pr
ocess

A foreground process is different from a background process in two ways:

1. Some foreground processes show the user an interface, through which the user can interact
with the program.


2. The user must wait for one foreground process to complete befo
re running another one.

To start a foreground process, enter a command at the prompt, e.g.,

$

command1

The next prompt will not appear until command1 finishes running.


Conclusion:


Should be written by students that what they understand by the program.


FAQ:

Q.1 Explain foreground process.

Q.2 Explain background process.



NAME OF FACULTY: