thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · web view00:1c.4...

73
ASSIGNMENT NO: 1 Aim: Implementation of Create/ rename/ delete a file using Unix/Linux commands Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like Vi,gedit or Nano Editor in Unix. Theory: All data in UNIX is organized into files. All files are organized into directories. These Directories are organized into a tree-like structure called the file system. A file system is a logical collection of files on a partition or disk. A partition is a container for information and can span an entire hard drive if desired. One file system per partition allows for the logical maintenance and management of differing file systems. Everything in Unix is considered to be a file, including physical devices such as DVD-ROMs, USB devices, floppy drives, and so forth. In UNIX there are three basic types of files: 1. Ordinary Files: An ordinary file is a file on the system that contains data, text, or program instructions. In this tutorial, you look at working with ordinary files. 2. Directories: Directories store both special and ordinary files. For users familiar with Windows or Mac OS, UNIX directories are equivalent to folders. 3. Special Files: Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts and enable you to access a single file using different names.

Upload: trinhliem

Post on 31-Jan-2018

223 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: 1

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

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like Vi,gedit or Nano Editor in Unix.

Theory:

All data in UNIX is organized into files. All files are organized into directories. These Directories are organized into a tree-like structure called the file system. A file system is a logical collection of files on a partition or disk. A partition is a container for information and can span an entire hard drive if desired. One file system per partition allows for the logical maintenance and management of differing file systems. Everything in Unix is considered to be a file, including physical devices such as DVD-ROMs, USB devices, floppy drives, and so forth.

In UNIX there are three basic types of files:

1. Ordinary Files: An ordinary file is a file on the system that contains data, text, or program instructions. In this tutorial, you look at working with ordinary files.

2. Directories: Directories store both special and ordinary files. For users familiar with Windows or Mac OS, UNIX directories are equivalent to folders.

3. Special Files: Some special files provide access to hardware such as hard drives, CD-ROM drives, modems, and Ethernet adapters. Other special files are similar to aliases or shortcuts and enable you to access a single file using different names.

A UNIX file system is a collection of files and directories that has the following properties:

It has a root directory (/) that contains other files and directories. Each file or directory is uniquely identified by its name, the directory in which it resides, and a unique identifier, typically called an inode. By convention, the root directory has an inode number of 2 and the lost+found directory has an inode number of 3. Inode numbers 0 and 1 are not used. File inode numbers can be seen by specifying the -i option to ls command. It is self contained. There are no dependencies between one filesystem and any other.

1. Navigating the File System:

Now that you understand the basics of the file system, you can begin navigating to the files you need. The following are commands you'll use to navigate the system:

Command Description

cat filename Displays a filename.

Page 2: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

cd dirname Moves you to the directory identified.

cp file1 file2 Copies one file/directory to specified location.

file filename Identifies the file type (binary, text, etc).

find filename dir Finds a file/directory.

head filename Shows the beginning of a file.

less filename Browses through a file from end or beginning.

ls dirname Shows the contents of the directory specified.

more filename Browses through a file from beginning to end.

mv file1 file2 Moves the location of or renames a file/directory.

pwd Shows the current directory the user is in.

rm filename Removes a file.

tail filename Shows the end of a file.

touch filename Creates a blank file or modifies an existing file.s attributes.

whereis filename Shows the location of a file.

which filename Shows the location of a file if it is in your PATH.

2. File Handling Operations:

2.1 Listing Files:

To list the files and directories stored in the current directory. Use the following command:

[scoe]$ ls

2.2 Creating Files:

You can use vi editor to create ordinary files on any Unix system. You simply need to give following command:

[scoe]$ vi filename

Above command would open a file with the given filename. You would need to press key i to come into edit mode. Once you are in edit mode you can start writing your content in the file as below: “Hello World!”Once you are done, do the following steps:

• Press key esc to come out of edit mode.

• Press two keys Shift + ZZ together to come out of the file completely or ESC + : WQ”

3. Set Permissions to File

Page 3: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

For further file handling operations are done with commands as per above table, for running file we have to set permissions for file execution. File ownership is an important component of UNIX that provides a secure method for storing files. Every file in UNIX has the following attributes:

• Owner permissions: The owner's permissions determine what actions the owner of the file can perform on the file.

• Group permissions: The group's permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.

• Other (world) permissions: The permissions for others indicate what action all other users can perform on the file.

Using ls -l command it displays various information related to file permission. To change file or directory permissions, you use the chmod (change mode) command. There are two ways to use chmod: symbolic mode and absolute mode

Symbolic mode is as

Chmod operator Description+ Adds the designated permission(s) to a file or directory.- Removes the designated permission(s) from a file or

Directory.= Sets the designated permission(s).The second way to modify permissions with the chmod command is to use a number to specify each set of permissions for the file. Each permission is assigned a value, as the following table shows, and the total of each set of permissions provides a number for that set.

Number Octal Permission Representation Ref0 No permission ---1 Execute permission --x2 Write permission -w-3 Execute and write permission: 1 (execute) + 2 (write)

= 3-wx

4 Read permission r--5 Read and execute permission: 4 (read) + 1 (execute) =

5r-x

6 Read and write permission: 4 (read) + 2 (write) = 6 rw-7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx

After setting permissionsExecuting program in this way:

[scoe]$ chmod 777 filename.sh[scoe]$ a./filename.sh

Page 4: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

4. umask: assign default permissions

You can use the built-in shell command umask to influence the default permissions given to the files you create. Every process has its own umask attribute; the shell’s built-in umask command sets the shell’s own umask, which is then inherited by commands that you run.

The umask is specified as a three-digit octal value that represents the permissions to take away. When a file is created, its permissions are set to whatever the creating program requests minus whatever the umask forbids. Thus, the individual digits of the umask allow the permissions shown in Table.

Permission encoding for umask

Octal Binary Perms Octal Binary Perms0 000 rwx 4 100 -wx1 001 rw- 5 101 -w-2 010 r-x 6 110 --x3 011 r-- 7 111 ---

For example, umask 027 allows all permissions for the owner but forbids write permission to the group and allows no permissions for anyone else. The default umask value is often 022, which denies write permission to the group and world but allows read permission. You cannot force users to have a particular umask value because they can always reset it to whatever they want. However, you can put a suitable default in the sample.profile file that you give to new users.

Algorithm: Write algorithm +flowchart on blank page as per your program.

Conclusion: Hence we have implemented file handling operations using Unix Commands.

Page 5: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO.: 2

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.

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like VI, gedit or Nano Editor in Unix.

Theory:

Unix uses a hierarchical file system structure, much like an upside-down tree, with root (/) at the base of the file system and all other directories spreading from there. T he directories have specific purposes and generally hold the same types of information for easily locating files.

Following are the directories that exist on the major versions of UNIX:

Directory Description / T his is the root directory which should contain only the directories

needed at the top level of the file structure./bin T his is where the executable files are located. They are available to all

user./dev T hese are device drivers./etc Supervisor directory commands, configuration files, disk configuration

files, valid user lists, groups, ethernet, hosts, where to send critical messages.

/lib Contains shared library files and sometimes other kernel-related files./boot Contains files for booting the system./home Contains the home directory for users and other accounts./mnt Used to mount other temporary file systems, such as cdrom and floppy

for the CDROM drive and floppy diskette drive, respectively/proc Contains all processes marked as a file by process number or other

information that is dynamic to the system./tmp Holds temporary files used between system boots/usr Used for miscellaneous purposes, or can be used by many users.

Includesadministrative commands, shared files, library files, and others

/var T ypically contains variable-length files such as log and print files and any other type of file that may contain a variable amount of data

/sbin Contains binary (executable) files, usually for system administration. For example fdisk and ifconfig utlities.

/kernel Contains kernel files

Page 6: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Mounting the File System:

A file system must be mounted in order to be usable by the system. T o see what is currently mounted (available for use) on your system, use this command:

$ mount /dev/vzfs on / type reiserfs (rw,usrquota,grpquota)

proc on /proc type proc (rw,nodiratime)

devpts on /dev/pts type devpts (rw)

T he /mnt directory, by Unix convention, is where temporary mounts (such as CD-ROM drives, remote network drives, and floppy drives) are located. If you need to mount a file system, you can use the mount command with the following syntax:

mount -t file_system_type device_to_mount directory_to_mount_to

For example, if you want to mount a CD-ROM to the directory /mnt/cdrom, for example, you can type:

$ mount -t iso9660 /dev/cdrom /mnt/cdrom

This assumes that your CD-ROM device is called /dev/cdrom and that you want to mount it to /mnt/cdrom. Refer to the mount man page for more specific information or type mount -h at the command line for help information.After mounting, you can use the cd command to navigate the newly available file system through the mountpoint you just made.

Unmounting the File System:

T o unmount (remove) the file system from your system, use the umount command by identifying the mountpoint or device For example, to unmount cdrom, use the following command:

$ umount /dev/cdrom

T he mount command enables you to access your file systems, but on most modern Unix systems, the auto mount function makes this process invisible to the user and requires no intervention.

/Proc Directory

The /proc directory is actually a pseudo-file system. The files in /proc mirror currently running system and kernel processes and contain information and statistics about them.

Page 7: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

$ cat /proc/devices

$ fgrep Mem /proc/meminfo

/proc/cpuinfo – information about CPU, /proc/meminfo – information about memory, /proc/loadvg – load average, /proc/partitions – partition related information, /proc/version – linux version

lspci - list all PCI devices

lspci is a command for displaying information about all PCI buses in the system and all devices connected to them.

lspci is a utility for displaying information about PCI buses in the system and 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 in lspciitself, 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, are probably intelligible only to experienced PCI hackers. For exact definitions of the fields, please consult either the PCI specifications or the header.hand /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.

lspci is useful when you want to diagnose problems or when you want to report bugs related to pci devices.

Algorithm:

Write algorithm on ruled page +Draw flowchart on blank page as per your program.

Conclusion: Hence we have implemented this program successfully.

ASSIGNMENT NO: 3

Page 8: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Aim: Write a shell program for Adding users and access rights.

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like VI, gedit or Nano Editor in UNIX.

Theory:

There are three types of accounts on a Unix system:

1. Root account: This is also called superuser and would have complete and unfettered control of the system. A superuser can run any commands without any restriction. This user should be assumed as a system administrator.

2. System accounts: System accounts are those needed for the operation of system-specific components for example mail accounts and the sshd accounts. These accounts are usually needed for some specific function on your system, and any modifications to them could adversely affect the system.

3. User accounts: User accounts provide interactive access to the system for users and groups of users. General users are typically assigned to these accounts and usually have limited access to critical system files and directories.

Unix supports a concept of Group Account which logically groups a number of accounts. Every account would be a part of any group account. Unix groups plays important role in handling file permissions and process management.

4. Managing Users and Groups:There are three main user administration files:

/etc/passwd: Keeps user account and password information. This file holds the majority of information about accounts on the Unix system.

/etc/shadow: Holds the encrypted password of the corresponding account. Not all the system supports this file.

/etc/group: This file contains the group information for each account. /etc/gshadow: This file contains secure group account information.

Check all the above files using cat command.

Following are commands available on the majority of Unix systems to create and manage accounts and groups:

Command Descriptionuseradd Adds accounts to the system.usermod Modifies account attributes.Userdel Deletes accounts from the system.groupadd Adds groups to the system.groupmodq Modifies group attributes.

Page 9: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Groupdel Removes groups from the system.5. Create an Account

Let us see how to create a new account on your Unix system. Following is the syntax to create a user's account:

$useradd -d homedir -g groupname -m -s shell -u userid accountname

Here is the detail of the parameters:

Command Description-d homedir Specifies home directory for the account.-g groupname Specifies a group account for this account.-m Creates the home directory if it doesn't exist.-s shell Specifies the default shell for this account.-u userid You can specify a user id for this account.Accountname Actual account name to be created

If you do not specify any parameter then system would use default values. The useradd command modifies the /etc/passwd, /etc/shadow, and /etc/group files and creates a home directory. Following is the example which would create an account mcmohd setting its home directory to/home/mcmohd and group as developers. This user would have Korn Shell assigned to it.

$ useradd -d /home/mcmohd -g developers -s /bin/ksh mcmohd

Before issuing above command, make sure you already have developers group created using groupadd command.

6. Setting user passwords

To set the user password run the following command:

$ passwd user_name

For example, to set the password for the user tioadmin, run the following command:

$ passwd tioadmin

Verify that you can log on with the user name and password before performing installation or configuration tasks that involve the user. On some systems, the password must be change the first time that the user logs on. Once an account is created you can set its password using the passwd command as follows:

$ passwd mcmohd20

Changing password for user mcmohd20.

Page 10: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

New UNIX password:

Retype new UNIX password:

passwd: all authentication tokens updated successfully.

When you type passwd accountname, it gives you option to change the password provided you are super user otherwise you would be able to change just your password using the same command but without specifying your account name.

7. Modify an Account:

The usermod command enables you to make changes to an existing account from the command line. It uses the same arguments as the useradd command, plus the -l argument, which allows you to change the account name. For example, to change the account name mcmohd to mcmohd20 and to change home directory accordingly, you would need to issue following command:

$ usermod -d /home/mcmohd20 -m -l mcmohd mcmohd20

8. Delete an Account:

The userdel command can be used to delete an existing user. This is a very dangerous command if not used with caution. There is only one argument or option available for the command: .r, for removing the account's home directory and mail file.

For example, to remove account mcmohd20, you would need to issue following command:

$ userdel -r mcmohd20

If you want to keep her home directory for backup purposes, omit the -r option. You can remove the home directory as needed at a later time.

9. Setting Permissions

There are 3 kinds of permissions:

r: read w: write x: execute

Note that the permission has special meaning for directories:

r: list the files in the directory, for instance with ls. w: add new elements to the directory. x: access files in the directory.

There are 3 levels of permission you can set:

user (the owner of the file/directory)

Page 11: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

group all

Note that when you create new users on the system, you're asked to assign them a group. The reason is simply for a better management of permissions.

10. How to know the permissions of a file

There are various ways. I think the most straightforward would be using ls -l. Example:

$ ls -l file

-rw-r----- 1 rahmu users 406 Jun 18 13:28 file

The first column indicates the permissions.

-rw-r-----, the first bit (-) indicates whether the file is a directory, a link or a regular file. Ignore it for now. Then the next 3 bits (rw-) indicate the user-level permissions. That means user rahmu has the right to read and write this file. The next three bits (r--) are the group-level permissions, this means that all the users who are in the group users will have read access. All the other users will have no permission at all (--). That means they cannot read the file, write it, nor execute it.

11. How to modify permissions.

It is usually done with the chmod utility. It supports many syntax, which one is best is debatable, but the following will make most sense after the above explanation:

$ chmod [who]operator[permissions] file

who is user, group or others. (There’s also all, for modifying all three levels at once). operator is + or -. permission is r, w or x.

Examples:chmod u-w file: remove write permission for user.chmod a+x file: add execute permission for all.

12. How to prevent access to your /home?

As mentioned, you need to define what you mean by access. If what you mean is read access, as in you don't want them to even list what's inside your directory, then the easiest would be to take the appropriate permissions off the /home directory. (Assuming they're connecting with a separate user).

$ chmod o-rwx ~

Algorithm:

Write algorithm on ruled page +Draw flowchart on blank page as per your program.Conclusion: Hence we have implemented this program successfully.

Page 12: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)
Page 13: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: 4

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.

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like VI, gedit or Nano Editor in Unix.

Theory:

Files on the UNIX system are grouped into directories, same as folders in a Windows environment. A directory is a collection of files and other (sub)directories. Note that files and directories must NOT have spaces in their names in a unix environment! The "highest" directory on a unix machine is called the "root directory", and is represented by a single slash (`/'). The root directory corresponds roughly to the Desktop on a Windows PC. The list of directories starting at root which lead to a specific file location is called the "directory path" or simply the "path" of the file. When typing a path, each directory is separated from the next by a (forward) slash. [This differs from a Windows machine which uses backslashes.]

Each user account on a unix server machine is associated with a directory called its "home directory" into which the user is automatically placed upon logging in.

A directory contains named references to other files. You can create directories with mkdir and delete them with rmdir if they are empty. You can delete nonempty directories with rm -r. The special entries “.” and “..” refer to the directory itself and to its parent directory; they may not be removed. Since the root directory has no parent directory, the path “/..” is equivalent to the path “/.” (and both are equivalent to /). A file’s name is stored within its parent directory, not with the file itself.

Symbolic notation Description. represents the current directory.. represents the parent directory of the current directory~ represents your home directory* represents any string of characters (a group wild card)? represents any single character (another wild card)

In fact, more than one directory (or more than one entry in a single directory) can refer to a file at one time, and the references can have different names. Such an arrangement creates the illusion that a file exists in more than one place at the same time.

Command Descriptionls dirname Shows the contents of the directory specified.mkdir dirname Creates the specified directory.

Page 14: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

pwd Shows the current directory the user is in.rmdir dirname Removes a directory.cd dirname Moves you to the directory identified.find filename dir Finds a file/directory.mv dir1 dir2 Moves the location of or renames directory.ls -d */ Listing for Directories onlytree –d Tree type display of Directoriesls -l | egrep `^d' Listing for Directories only

Algorithm:

Write algorithm on ruled page +Draw flowchart on blank page as per your program.

Conclusion: Hence we have implemented this program successfully.

Page 15: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: 5

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

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like Vi,gedit or Nano Editor in Unix.

Theory:

When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.

Whenever you issue a command in UNIX, it creates, or starts, a new process. When you tried out the ls command to list directory contents, you started a process. A process, in simple terms, is an instance of a running program. The operating system tracks processes through a five digit ID number known as the pid or process ID . Each process in the system has a unique pid.Pids eventually repeat because all the possible numbers are used up and the next pid rolls or starts over. At any one time, no two processes with the same pid exist in the system because it is the pid that UNIX uses to track each process.

COMPONENTS OF A PROCESS

A process consists of an address space and a set of data structures within the kernel. The address space is a set of memory pages1 that the kernel has marked for the process’s use. It contains the code and libraries that the process is executing, the process’s variables, its stacks, and various extra information needed by the kernel while the process is running. Because UNIX and Linux are virtual memory systems, there is no correlation between a page’s location within a process’s address space and its location inside the machine’s physical memory or swap space. The kernel’s internal data structures record various pieces of information about each process. Here are some of the more important of these:

• The process’s address space map

• The current status of the process (sleeping, stopped, runnable, etc.)

• The execution priority of the process

• Information about the resources the process has used

• Information about the files and network ports the process has opened

• The process’s signal mask (a record of which signals are blocked)

Page 16: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

• The owner of the process

1. Starting a Process:

When you start a process (run a command), there are two ways you can run it:

• Foreground Processes

• Background Processes

Foreground Processes:

By default, every process that you start runs in the foreground. It gets its input from the

keyboard and sends its output to the screen.

[SCOE] $ ls ch*.doc

Background Processes:

A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits. The advantage of running a process in the background is that you can run other commands; you do not have to wait until it completes to start another! The simplest way to start a background process is to add an ampersand ( &) at the end of the command.

[SCOE]$ ls ch*.doc &

2. Listing Running Processes:

It is easy to see your own processes by running the ps (process status) command as follows:

[SCOE]$ ps

One of the most commonly used flags for ps is the -f ( f for full) option, which provides more information, Here is the description of all the fileds displayed by ps -f command

Column DescriptionUID User ID that this process belongs to (the person running it).PID Process ID.PPID Parent process ID (the ID of the process that started it).C CPU utilization of process.STIME Process start time.TTY Terminal type associated with the processTIME CPU time taken by the process.CMD The command that started this process.

There are other options which can be used along with ps command:

Page 17: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Option Description-a Shows information about all users-x Shows information about processes without terminals.-u Shows additional information like -f option.-e Display extended information.

3. Stopping Processes:

Ending a process can be done in several different ways. Often, from a console-based command, sending a CTRL + C keystroke (the default interrupt character) will exit the command. This works when process is running in foreground mode. If a process is running in background mode then first you would need to get its Job ID using ps command and after that you can use kill command to kill the process as follows:

[SCOE]$ ps –f/* using $ kill PID */[SCOE]$ kill 6738Terminated

4. The top command

The top command is a very useful tool for quickly showing processes sorted by various criteria. It is an interactive diagnostic tool that updates frequently and shows information about physical and virtual memory, CPU usage, load averages, and your busy processes. Here is simple syntax to run top command and to see the statistics of CPU utilization by different processes:

[SCOE]$ top

5. NICE AND RENICE: SETTING SCHEDULING PRIORITY

The “niceness” of a process is a numeric hint to the kernel about how the process should be treated in relation to other processes contending for the CPU. A high nice value means a low priority for your process: you are going to be nice. A low or negative value means high priority: you are not very nice. The range of allowable niceness values varies among systems. The most common range is -20 to +19. Some systems use a range of a similar size beginning at 0 instead of a negative number (typically 0 to 39). A process’s nice value can be set at the time of creation with the nice command and adjusted later with the renice command. nice takes a command line as an argument, and renice takes a PID or (sometimes) a username.

Some examples:

$ nice -n 5 ~/bin/longtask // Lowers priority (raise nice) by 5$ sudo renice -5 8829 // Sets nice value to -5$ sudo renice 5 -u boggs // Sets nice value of boggs’s procs to 5Algorithm:

Write algorithm on ruled page +Draw flowchart on blank page as per your program.

Page 18: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Conclusion: Hence we have implemented this program successfully.

Page 19: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: 6

Aim: Write a Program in which use of 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

Software Requirements: 64-BIT Fedora 17 or latest 64-BIT Update of Equivalent Open source OS, Latest Open source update of Eclipse Programming frame work, Editor like Vi,gedit or Nano Editor in Unix.

Theory:

1. Operating System Details

The uname command reports basic information about a computer's software and hardware. The uname command is used to print system information like kernel version, kernel release etc. Its syntax is

$ uname [options]

Short Option Long Option Option Description-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

Page 20: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

When used without any options, uname reports the name, but not the version number, of the kernel(i.e., the core of the operating system). Thus, on a system running some distribution (i.e., version) ofLinux, it will display the word Linux on the monitor screen. The -a (i.e., all) option tells uname to provide the following information: the name of the kernel,network node host name (e.g., localhost.localdomain), kernel version number and release level (e.g., 2.4.20-6), kernel release date, machine hardware name, CPU (central processing unit) type, hardware platform and operating system name (e.g., GNU/Linux). Options can be combined to produce any combination of output desired, although the order of the output is the same as that provided by the -a option rather than that in which the options are listed. For example, the following will display the kernel name and version number inclusive of the release level:

uname -sr

The output will be in the same order if the options are transposed, i.e.,

uname -rs

The --help option displays brief documentation for uname, and the --version option provides uname's version number.

2. User Details

w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment.

who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location.

finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'.

last -1 username --- tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins.

whoami --- returns your username. Sounds useless, but isn't. You may need to find out who it is who forgot to log out somewhere, and make sure *you* have logged out.

Syntax

$ who Options [ file ]

Page 21: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Options Description-a Process /var/adm/utmp or the named file with -b, -d, -l, -p, -r, -t, -T, and -u

options turned on.

-b Indicate the time and date of the last reboot.

-d Display all processes that have expired and not been re spawned by init .

-H Output column headings above the regular output.

-l List only those lines on which the system is waiting for someone to login.

-m Output only information about the current terminal.

-p List any other process which is currently active and has been previously spawned by init .

-q Display only the names and the number of users currently logged on. When this option is used, all other options are ignored.

-u List only those users who are currently logged in. The name is the user's login name. The line is the name of the line as found in the directory /dev. The time is the time that the user logged in. The idle column contains the number of hours and minutes since activity last occurred on that particular line. A dot (.) indicates that the terminal has seen activity in the last minute and is therefore ``current''. If more than twenty-four hours have elapsed or the line has not been used since boot time, the entry is marked old. This field is useful when trying to determine whether a person is working at the terminal or not. The pid is the process-ID of the user's shell. The comment is the comment field associated with this line as found in /sbin/inittab. This can contain information about where the terminal is located, the telephone number of the dataset, terminal if hard-wired, and so forth.

Am I In the "C" locale, limit the output to describing the invoking user, equivalent to the -m option. The am and i or I must be separate arguments.

file Specify a path name of a file to substitute for the database of logged-on users that who uses by default.

3. Hostname

Hostname is the program that is used to either set or display the current host, domain or node name of the system. These names are used by many of the networking programs to identify the machine. It is used to Set or print name of current host system. A host name is a name that is assigned to a host (i.e., a computer connected to the network) that uniquely identifies it on

Page 22: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

a network and thus allows it to be addressed without using its full IP address. Domain names are user-friendly substitutes for numeric IP addresses.

The basic syntax for the hostname command is

$ hostname [options] [new_host_name]

When used without any options or arguments (i.e., input data), hostname displays the current host and domain names of the local machine (i.e., the computer that is currently being used). The default host and domain name is typically localhost.localdomain. When a name is provided as an argument, it becomes the new host name. A change in the host name can only be performed by the root (i.e., administrative) account, which can be accessed using the su(i.e., substitute user) command. For example, to change the host name to computer_01, the following would be used:

$ hostname computer_01

$ hostedPerforming the above command would display the current host's numerical id,

for example:

46a603ch

Algorithm: Write algorithm +flowchart on blank page as per your program.

Conclusion: Hence we have implemented this program using Unix Commands.

Page 23: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO:-7

Aim: C/C++ program for creating the child process using fork system call.

Theory: Various functions are use for creation of processes, waiting one process till previous program are executing, execute the program, exiting/terminating the current program etc…. functions are as below.

Explanations:

int pid=fork():

This command is use to create a process. Using this function we can create a child process of current process. On success, the PID of the child process is returned in the parent,and 0 is returned in the child. On failure, -1 is returned in the parent, no child process is created, and errno is set appropriately.

Exec():

It is used for executing a process or program. It copies program image onto running process.The exec() functions return only if an error has occurred. Thereturn value is -1, and errno is set to indicate the error.

Wait():

It wait one process till another task is complete. It is used for synchronizing execution current process with previous process which is created by fork().All of these system calls are used to wait for state changes in a child of the calling process, and obtain information about the child whose state has changed. On success, returns the process ID of the terminated child;on error, -1 is returned.

Exit():

It complete execution of process also this function terminate current process. The exit() function causes normal process termination and the value of status is returned to the parent. The exit() function does not return.

Pid =Getpid():

This function is used to get process identification getpid() returns a process id of the calling process. This is often used by routines that generate unique temporary file names. These functions are always successful.      Getppid():

This function is used to get process identification .getppid() returns the process id of the parent of the calling process.

Page 24: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Conclusion: Hence we examine the creation of child process using fork() system call.

Program:

#include<stdio.h>#include<unistd.h>int main(){intpid;

pid=fork();

if(pid==0){printf("\n After fork");printf("\n The new child process created by fork system call %d\n", getpid());printf("\n The parent process id is :- %d ", getppid());}else {printf("\n Befor fork");

printf("\n The parent process id is :- %d ", getpid());printf("\n parent excuted successfully\n");

}return 0; }Output:

[student@localhost ~]$ gccfork.c[student@localhost ~]$ ./a.out

Befor fork

The parent process id is :- 1792 parentexcuted successfully After fork The new child process created by fork system call 1793

The parent process id is :- 1792 [student@localhost ~]$

ASSIGNMENT NO:-8

Page 25: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Aim: C/C++ Program to assign nice values to processes and dynamically monitor them

Theory:

On a Linux machine, there are hundreds of processes that are continuously running for some or the other tasks. Linux Kernel does a fantastic job in mediating between these processes and allotting CPU to these processes.

An interesting question arises when you read that line "kernel allocates CPU to all the process".

Computer is made to do whatever task is given, so how will kernel come to know about a particular process, which i want to be on top of the list on priority?

The answer to that question is, "You can in fact ask the kernel to put a particular process of yours, on higher priority than others".

This can be easily achieved with the help of a command called "Nice" in Linux.

Nice Command In Linux Do:-

With the help of Nice command in Linux you can set process priority. If you give a process a higher priority, then Kernel will allocate more cpu time to that process.

By default when a programe is launched in Linux, it gets launched with the priority of '0'. However you can change the priority of your programes by either of the following methods.

1. You can launch a programe with your required priority.

2. Or you can also change the priority of an already running process.

Priority of a processes running in Linux:-

You can see the process priority by running ps command with "-al" option as shown below.

1

2

3

F   UID   PID  PPID PRI  NI    VSZ   RSS WCHAN  STAT TTY        TIME COMMAND

4     0  4075  4057  15   0   4664  1504 -      Ss+  pts/0      0:00 -bash

4     0  4481     1  15   0   1656   436 -      Ss+  tty2       0:00 /sbin/minge

Page 26: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

4

5

6

7

8

tty tty2

4     0  4485     1  15   0   1656   436 -      Ss+  tty3       0:00 /sbin/minge

tty tty3

4     0  4488     1  19   0   1656   452 -      Ss+  tty4       0:00 /sbin/minge

tty tty4

The column that starts with "NI" shows the nice value(priority of the process). You can clearly see that most of them has got a '0' priority.

You can also see the process priority(nice value) using "top" command.Below shown is an example output of top command.

1

2

3

4

5

6

7

8

9

10

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND

 8018 root      15   0  2192  908  716 R  2.0  0.2   0:00.01 top

    1 root      15   0  2064  624  536 S  0.0  0.1   0:03.13 init

    2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0

    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0

    4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0

    5 root      10  -5     0    0    0 S  0.0  0.0   0:00.24 events/0

    6 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper

    7 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 kthread

   10 root      10  -5     0    0    0 S  0.0  0.0   0:02.73 kblockd/0

In the top command output shown above nice value(process priority) can be seen from the "NI" column.

Understanding Nice Command in Linux

The syntax of nice command in linux is quite simple.Help for nice command can be listed by the following method.

1 [root@myvm1 ~]# nice --help

Page 27: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Usage: nice [OPTION] [COMMAND [ARG]...]

Run COMMAND with an adjusted niceness, which affects process scheduling.

With no COMMAND, print the current niceness.  Nicenesses range from

-20 (most favorable scheduling) to 19 (least favorable).

  

  -n, --adjustment=N   add integer N to the niceness (default 10)

      --help     display this help and exit

      --version  output version information and exit

  

NOTE: your shell may have its own version of nice, which usually supersedes

the version described here.  Please refer to your shell's documentation

for details about the options it supports.

  

Report bugs to <[email protected]>.

-n and --adjustment can be used to set the priority of your process.You can also use -<required number> to set the process priority to that value.

For example

nice -10 <command name> Will set a process with the priority of "10".

Running nice command with no options will give you the priority with which the current shell is running.

1

2

3

[root@myvm1 ~]# nice

0

[root@myvm1 ~]#

Range of nice priority values:-

Page 28: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Process priority values range from -20 to 19.

Program

#include<stdio.h>#include<stdlib.h>main(){Printf("*****PROGRAM FOR NICE****\n";system("nice");}

Page 29: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: -9

Aim: Write a C/C++ script to display all logged in users.

Theory:

Structure passwdpasswd is a tool on most Unix and Unix-like operating systems used to change a user's password. The password entered by the user is run through a key derivation function to create a hashed version of the new password, which is saved. Only the hashed version is stored; the entered password is not saved for security reasons.The passwd command may be used to change passwords for local accounts, and on most systems, can also be used to change passwords managed in a distributed authentication mechanism such as NIS, Kerberos, or LDAP.

Real User NameA name used to gain access to a computer system. Usernames, and often passwords, are required in multi-user systems. In most such systems, users can choose their own usernames and passwords. Usernames are also required to access some bulletin board and online services.

getpwuid (getuid)The getpwuid() function shall search the user database for an entry with a matching uid. The getpwuid() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe. The getpwuid() function shall return a pointer to a structpasswd with the structure as defined in <pwd.h> with a matching entry if found. A null pointer shall be returned if the requested entry is not found, or an error occurs. On error, errno shall be set to indicate the error.

uidThe UID is the actual information that the operating system uses to identify the user; usernames are provided merely as a convenience for humans. If two users are assigned the same UID ,UNIX views them as the same user, even if they have different usernames and passwords. Two users with the same UID can freely read and delete each other's files and can kill each other's programs.

gid

Page 30: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Every UNIX user belongs to one or more groups . Like user accounts, groups have both a groupname and a group identification number ( GID). As the name implies, UNIX groups are used to group users together. As with usernames, groupnames and numbers are assigned by the system administrator when each user's account is created. Groups can be used by the system administrator to designate sets of users who are allowed to read, write, and/or execute specific files, directories, or devices.

Steps For Execution of a C/C++ Program1) First write c/c++ program using any editor like notepad2) Save the program using .c/.cpp extension.3) Now in compilation the code is converted into equivalent machine instruction.4) Check the errors given by compiler if any.5) After solving all errors reedit the program.6) Finally you will get the output.

Algorithm:

1) Initialize the program using the header files and required variables2) Get input from user3) Uid=user id, gid= group id4) Who= logged in users5) Cout to display all outputs6) End the program7) stop

Conclusion: We have successfully completed a program to display all logged in users.

Program:

#include<pwd.h>#include<sys/types.h>#include<unistd.h>#include<stdio.h>main(){structpasswd *procuid;procuid=getpwuid(getuid());printf("\n The Real User Name is %s ", procuid->pw_gecos);printf("\n The Login Name is %s ", procuid ->pw_name);printf("\n The Home Directory is %s", procuid ->pw_dir);printf("\n The Login Shell is %s ", procuid ->pw_shell);

Page 31: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

printf("\n The uid is %lu ", (unsigned long) getpwuid(getuid())->pw_uid);printf("\n The gid is %lu \n\n", (unsigned long) getpwuid(getuid())->pw_gid);}#include<stdio.h>#include<unistd.h>#include<stdlib.h>#include<iostream>using namespace std;main(){cout<<"*****PROGRAM TO SHOW LOGGED IN USER AND NUMBER OF LOGGED IN USER****\n";cout<<"LOGGED IN USERS ARE:-\n";cout<<system("who -u");cout<<"NUMBER OF LOGGED IN USERS ARE :-\n";cout<<system(" who -u| wc -l");

}Output:

sandesh@Inspiron-1545:~$ g++ assign1.cpp

sandesh@Inspiron-1545:~$ ./a.out

The Real User Name is cl2,,,

Page 32: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO:-10

Aim: C/C++ program to display list of devices connected to your system including physical names and instances.

Theory:

System callIn computing, a system call is how a program requests a service from an operating system's kernel. This may include hardware related services (e.g. accessing the hard disk), creating and executing new processes, and communicating with integral kernel services (like scheduling). System calls provide an essential interface between a process and the operating system.

Header filesA header file is a file containing C declarations and macro definitions to be shared between several source files. You request the use of a header file in your program by including it, with the C preprocessing directive ‘#include’. Your own header files contain declarations for interfaces between the source files of your program. stdlib.h is the header of the general purpose standard library of C programming language which includes functions involving memory allocation, process control, conversions and others. It is compatible with C++ and is known as cstdlib in C++. The name "stdlib" stands for "standard library".

lspcilspci is a command for displaying information about all PCI buses in the system and all devices connected to them. lspci is useful when you want to diagnose problems or when you want to report bugs related to pci devices.

lspci [options]

lsusbThe lsusb command lists all USB devices that are present in the system, for example:Ex. lsusb

Algorithm:

1) Initialize the program using the header files and required variables2) Get input from user using cin3) lspci=list of all pci buses, lsusb= list of devices connected to system4) cout to display all outputs5) End the program

Page 33: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

6) Stop

System ()A system is a set of interacting or interdependent components forming an integrated wholeor a set of elements (often called ‘components’) and relationships which are different from relationships of the set or its elements to other elements or sets. A system has structure, it contains parts (or components) that are directly or indirectly related to each other. A system has behavior; it contains processes that transform inputs into outputs.

Conclusion: We successfully implemented a c/c++ program to display list of devices connected to system.

Program:

C Code:-

#include<stdio.h>

#include<stdloib.h>

main()

{

printf(“LIST OF DEVICES CONNECTED TO SYSTEM”);

system ("lspci");

}

C++ code:-

#include <iostream>#include <stdlib.h>

using namespace std;

int main(){string name;

Page 34: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

name = system ("lspci");cout<< name;

name = system ("lsusb");cout<< name;return 0;

}Output:

cl2@Inspiron-1545:~$ g++ ex.cppcl2@Inspiron-1545:~$ ./a.out00:00.0 Host bridge: Intel Corporation Mobile 4 Series Chipset Memory Controller Hub (rev 07)00:02.0 VGA compatible controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)00:02.1 Display controller: Intel Corporation Mobile 4 Series Chipset Integrated Graphics Controller (rev 07)00:1a.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #4 (rev 03)00:1a.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #5 (rev 03)00:1a.2 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #6 (rev 03)00:1a.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #2 (rev 03)00:1b.0 Audio device: Intel Corporation 82801I (ICH9 Family) HD Audio Controller (rev 03)00:1c.0 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 1 (rev 03)00:1c.1 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 2 (rev 03)00:1c.2 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 3 (rev 03)00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)00:1d.0 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #1 (rev 03)00:1d.1 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #2 (rev 03)00:1d.2 USB controller: Intel Corporation 82801I (ICH9 Family) USB UHCI Controller #3 (rev 03)00:1d.7 USB controller: Intel Corporation 82801I (ICH9 Family) USB2 EHCI Controller #1 (rev 03)00:1e.0 PCI bridge: Intel Corporation 82801 Mobile PCI Bridge (rev 93)

Page 35: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

00:1f.0 ISA bridge: Intel Corporation ICH9M LPC Interface Controller (rev 03)00:1f.2 SATA controller: Intel Corporation 82801IBM/IEM (ICH9M/ICH9M-E) 4 port SATA Controller [AHCI mode] (rev 03)00:1f.3 SMBus: Intel Corporation 82801I (ICH9 Family) SMBus Controller (rev 03)09:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8040 PCI-E Fast Ethernet Controller (rev 13)0c:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g LP-PHY (rev 01)Bus 001 Device 003: ID 0bda:0158 Realtek Semiconductor Corp. USB 2.0 multicard readerBus 001 Device 004: ID 0c45:63ee MicrodiaBus 002 Device 003: ID 0781:5567 SanDisk Corp. Cruzer BladeBus 003 Device 002: ID 0a5c:4500 Broadcom Corp. BCM2046B1 USB 2.0 Hub (part of BCM2046 Bluetooth)Bus 007 Device 002: ID 046d:c05b Logitech, Inc. M-U0004 810-001317 [B110 Optical USB Mouse]Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hubBus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hubBus 003 Device 003: ID 413c:8161 Dell Computer Corp. Integrated KeyboardBus 003 Device 004: ID 413c:8162 Dell Computer Corp. Integrated Touchpad [Synaptics]Bus 003 Device 005: ID 413c:8160 Dell Computer Corp. Wireless 365 Bluetooth

Page 36: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO:-11

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

Theory:

structure sysinfo

During setup initialization, Install Shield sets the members of the SYSINFO structure variable to identify the operating platform of the target computer. By inspecting the values assigned to members of this variable, your script can determine the following information:

The operating system The major and minor version number The subversion The version of Internet Explorer The latest service pack installed if Windows NT If the end user has administrator rights under Windows NT If the end user is a power user If the system is 64-bit The language IDs of the system language, user language, and operating system

language On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

Algorithm:

1) Initialize the program using certain header files2) Declare necessary variables3) In main create structure sysinfo4) Cout is used to print the output5) End the program using return 06) stop

Conclusion: We have successfully completed the c/c++ program to identify the available memory in system.

Page 37: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Program:

#include<sys/sysinfo.h>#include<unistd.h>#include<stdio.h>#include<iostream>

using namespace std;

int main(){structsysinfo a;unsigned long tot;sysinfo(&a);cout<<"\n memory units "<<a.mem_unit<<"Units";

cout<<"\n total Ram "<<a.totalram;

tot=a.mem_unit*a.totalram;cout<<"\n Total useable main memory units "<<tot;

return 0;}

Output:

cl2@Inspiron-1545:~$ g++ a.cpp

cl2@Inspiron-1545:~$ ./a.out

memory units 1Units

total Ram 3118276608

Total useable main memory units 3118276608cl2@Inspiron-1545:~$

Page 38: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: -12

Aim: Write a JavaScript program to display all logged in users. Count the no of logged in users. Write a program to create, display foreground and background processes for selected user and display its status.

Theory:

foreground processBy default, every process that you start runs in the foreground. It gets its input from the keyboard and sends its output to the screen. You can see this happen with the ls command. If I want to list all the files in my current directory, I can use the following command:

$ls ch*.doc

This would display all the files whose name start with ch and ends with .doc:

ch01-1.doc ch010.doc ch02.doc ch03-2.doc ch04-1.doc ch040.doc ch05.doc ch06-2.docch01-2.doc ch02-1.doc

The process runs in the foreground, the output is directed to my screen, and if the ls command wants any input (which it does not), it waits for it from the keyboard. While a program is running in foreground and taking much time, we cannot run any other commands (start any other processes) because prompt would not be available until program finishes its processing and comes out.

background process

A background process runs without being connected to your keyboard. If the background process requires any keyboard input, it waits. The simplest way to start a background process is to add an ampersand ( &) at the end of the command.

$ls ch*.doc &ch01-1.doc ch010.doc ch02.doc ch03-2.doc ch04-1.doc ch040.doc ch05.doc ch06-2.docch01-2.doc ch02-1.doc

Here if the ls command wants any input (which it does not), it goes into a stop state until I move it into the foreground and give it the data from the keyboard. That first line contains information about the background process - the job number and process ID. You need to know the job number to manipulate it between background and foreground.

dsReport how much free disk space is available for each mount you have.

Eg. df

Page 39: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

In the above example when performing just the df command with no additional switches or specification of the file or directory you would get a listing of all file systems and their used and available space.

whoLists who is logged on your machine

The formal syntax for who is:

who [option]

psThe ps (i.e., process status) command is used to provide information about the currently running processes, including their process identification numbers (PIDs). A process, also referred to as a task, is an executing (i.e., running) instance of a program. Every process is assigned a unique PID by the system.

The basic syntax of ps is,

ps [options]

When ps is used without any options, it sends to standard output, which is the display monitor by default, four items of information for at least two processes currently on the system: the shell and ps.

Algorithm:1) initialize the program using header files2) declare certain variables/functions3) who=who is logged in4) ps=running process5) use of display functions6) end in proper manner7) stop

Conclusion: We successfully done a Java Script program to display all logged in users.Program:

import java.io.BufferedReader;import java.io.InputStreamReader;public class assign7{public static void main(String[] args){int count=0;try{String line,line1;Process p=Runtime.getRuntime().exec("who");

Page 40: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

//getRuntime().exec("who");BufferedReader input = new BufferedReader(new

InputStreamReader(p.getInputStream()));

while((line=input.readLine())!=null){System.out.println(line);count++;}System.out.println("No.of users are:"+count);input.close();Process q=Runtime.getRuntime().exec("ps");BufferedReader input1 = new BufferedReader(new

InputStreamReader(q.getInputStream()));while((line1=input1.readLine())!=null){System.out.println(line1);//count++;

}//System.out.println("No.of users are:"+count);input.close();}catch(Exception e){e.printStackTrace();}}}

Output: [student@localhost ~]$ javac assign7.java[student@localhost ~]$ java assign7student :0 2013-10-09 08:29 (:0)student pts/0 2013-10-09 11:57 (:0)No.of users are:2 PID TTY TIME CMD 5413 pts/0 00:00:00 bash 5733 pts/0 00:00:00 java 5747 pts/0 00:00:00 ps

ASSIGNMENT NO: -13

Page 41: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Aim: Java program to display the list of devices connected to your system including physical names and its instance number.

Theory:

class processThe class Process provides methods for performing input from the process, performing output to the process, waiting for the process to complete, checking the exit status of the process, and destroying (killing) the process. The methods that create processes may not work well for special processes on certain native platforms, such as native windowing processes, daemon processes, Win16/DOS processes on Microsoft Windows, or shell scripts. By default, the created sub process does not have its own terminal or console.

Data Types1)byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.

2) short: The short data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).

3) int: The int data type is a 32-bit signed two's complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive).

4)long: The long data type is a 64-bit signed two's complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).

5)float: The float data type is a single-precision 32-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion. As with the recommendations for byte and short, use a float (instead of double) if you need to save memory in large arrays of floating point numbers.

6)double: The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is beyond the scope of this discussion. For decimal values,

Page 42: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency.

7)boolean: The boolean data type has only two possible values: true and false. Use this data type for simple flags that track true/false conditions. This data type represents one bit of information, but its "size" isn't something that's precisely defined.

8)char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive).

Buffer Reader The Buffered Reader class provides buffering to your Reader's. Buffering can speed up IO quite a bit. Rather than read one character at a time from the network or disk, you read a larger block at a time. This is typically much faster, especially for disk access and larger data amounts.

Input Stream ReaderAn InputStreamReader is a bridge from byte streams to character streams: It reads bytes and decodes them into characters using a specified charset. The charset that it uses may be specified by name or may be given explicitly, or the platform's default charset may be accepted.

get Input Stream( )The goal of input stream is to abstract different ways to input, whether the stream is a file, a web page, or the screen shouldn’t matter. All that matter is that you receive information from the stream. Input stream is used for many things you read from.

Readline ( )Method reads the next line of text from this file. This method successively reads bytes from the file, starting at the current file pointer, until it reaches a line terminator or the end of the file. Each byte is converted into a character by taking the byte's value for the lower eight bits of the character and setting the high eight bits of the character to zero.

Runtime.getRuntime().exeThis retrieves the current Java Runtime Environment. That is the only way to obtain a reference to the Runtime object. With that reference, you can run external programs by invoking the Runtime class's exec() method. Developers often call this method to launch a browser for displaying a help page in HTML.

Algorithm:

8) initialize the program using header files9) declare certain variables/functions

Page 43: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

10) who=who is logged in11) ps=running process12) use of display functions13) end in proper manner14) stop

Conclusion: We successfully implemented a Java program to display the list of devices connected to your system including physical names and its instance number.

Program:

import java.io.*;

class ListDevice{

public static void main(String args[]) throws IOException {

String line = null;Process ps = Runtime.getRuntime().exec("lspci");BufferedReader reader = new BufferedReader(new

InputStreamReader(ps.getInputStream()));

System.out.println("Listing Devices using lspci command ");

while((line = reader.readLine())!= null){

System.out.println(line);}

ps = Runtime.getRuntime().exec("cat /proc/devices");reader = new BufferedReader(new

InputStreamReader(ps.getInputStream()));

System.out.println("Reading Device File ");

while((line = reader.readLine())!= null){

System.out.println(line);}

}}

Page 44: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Output:

[student@localhost ~]$ javac ListDevice.java[student@localhost ~]$ java ListDeviceListing Devices using lspci command 00:00.0 Host bridge: Intel Corporation 4 Series Chipset DRAM Controller (rev 03)00:01.0 PCI bridge: Intel Corporation 4 Series Chipset PCI Express Root Port (rev 03)00:02.0 VGA compatible controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)00:02.1 Display controller: Intel Corporation 4 Series Chipset Integrated Graphics Controller (rev 03)00:1b.0 Audio device: Intel Corporation NM10/ICH7 Family High Definition Audio Controller (rev 01)00:1c.0 PCI bridge: Intel Corporation NM10/ICH7 Family PCI Express Port 1 (rev 01)00:1d.0 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #1 (rev 01)00:1d.1 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #2 (rev 01)00:1d.2 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #3 (rev 01)00:1d.3 USB controller: Intel Corporation NM10/ICH7 Family USB UHCI Controller #4 (rev 01)00:1d.7 USB controller: Intel Corporation NM10/ICH7 Family USB2 EHCI Controller (rev 01)00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev e1)00:1f.0 ISA bridge: Intel Corporation 82801GB/GR (ICH7 Family) LPC Interface Bridge (rev 01)00:1f.1 IDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01)00:1f.2 IDE interface: Intel Corporation NM10/ICH7 Family SATA Controller [IDE mode] (rev 01)00:1f.3 SMBus: Intel Corporation NM10/ICH7 Family SMBus Controller (rev 01)02:00.0 Ethernet controller: Broadcom Corporation NetLink BCM57780 Gigabit Ethernet PCIe (rev 01)Reading Device File Character devices: 1 mem 4 /dev/vc/0 4 tty 4 ttyS 5 /dev/tty 5 /dev/console

Page 45: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

5 /dev/ptmx 7 vcs 10 misc 13 input 14 sound 21 sg 29 fb 99 ppdev116 alsa128 ptm136 pts162 raw

Block devices:259 blkext 7 loop 8 sd 9 md 11 sr 65 sd 66 sd 67 sd 68 sd 69 sd 70 sd 71 sd128 sd

Page 46: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: - 14

Aim: Write a shell program to convert all lowercase letter in file to uppercase letter.

Theory:

#!/bin/bash It is called a shebang. It consists of a number sign and an exclamation point character (#!), followed by the full path to the interpreter such as /bin/bash. All scripts under UNIX and Linux execute using the interpreter specified on a first line.The first thing you should notice is that the script starts with ‘#!’. This is known as an interpreter line. If you don’t specify an interpreter line, the default is usually the Bourne shell (/bin/sh). However, it is best to specify this line anyway for consistency.

if The first command we will look at is if. The if command is fairly simple on the surface; it makes a decision based on a condition. The if command has three forms:

# First form ifcondition ; thencommandsfi

# Second formifcondition ; thencommandselsecommandsfi

# Third formifcondition ; thencommandselifcondition ; thencommandsfi

In the first form, if the condition is true, then commands are performed. If the condition is false, nothing is done.In the second form, if the condition is true, then the first set of commands is performed. If the condition is false, the second set of commands is performed.In the third form, if the condition is true, then the first set of commands is performed. If the condition is false, and if the second condition is true, then the second set of commands is performed.EX.if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then

Page 47: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

echo "You have access!"elseecho "ACCESS DENIED!"fi

tr ‘[a-z]’ ‘[A-Z]’The tr command is used to translate specified characters into other characters or to delete them.

The general syntax of tr is

tr [options] set1 [set2]

When used without any options, tr will replace the characters provided in set1 with those provided in set1.

Similar to the above example, we can translate the uppercase letters to small letters.

Conclusion: We have successfully written the shell program to convert all lowercase letters in file to uppercase letter.

Program :

#!/bin/bash

# get filename

echo -n "Enter File Name : "

readfileName

# make sure file exits for reading

if [ ! -f $fileName ]; then

echo "Filename $fileName does not exists"

exit 1

fi

# convert lowercase to uppercase using tr command

tr '[a-z]' '[A-Z]' < $fileName

Output :

[student@localhost ~]$ cat>abhi

Page 48: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

helloi am fine[student@localhost ~]$ ./2.shEnter File Name :amanHELLO I AM FINE[student@localhost ~]$

Page 49: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO: - 15

Aim: Java program to identify the available memory in the system.

Theory:

Java Features :

1.Java is very simple programming language. Even though you have no programming background you can learn this language comfortably. 2.Java is popular beco’z it is an object oriented programming language like C++. 3.Platform independence is the most exciting feature of java. That means programs in java can be executed on variety of systems. This feature is based on the goal “write once, run anywhere and at anytime, forever”. 4.Java supports multithreaded programming which allows a programmer to write such a program that can be perform many tasks simultaneously. 5.Thus robustness is the essential criteria for the java programs. 6.Java is designed for distributed systems. Hence two different objects on different computer can communicate with each other. This can be achieved by RMI(Remote Method Invocation)

Import :In java if a fully qualified name, which includes the package and the class name,is given then the complier can easily locate the source code or classes . Import statement is a way of giving the proper location for the the complier to find that particularclass.

For example, the following line would ask compiler to load all the classes available in directory java installation/java/io:

import java.io.*;

Clan process:Clans are introduced as a basic concept of an operating system kernel. They permit full algorithmic control of process interaction in a user definable but secure way. All communication across a clan’s borderline is inspected and possibly modified by the clan’s so called chief task. Thus the mechanism can be used for protection, remote communication, debugging, event tracing, emulation, connecting heterogeneous systems and even process migration

Public void close():Closes this reader. This implementation closes the buffered source reader and releases the buffer. Nothing is done if this reader has already been closed

Page 50: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Steps for Execution:

1) Phase 1 consists of editing a file. This is accomplished with an editor program. The programmer types a java program using the editor like notepad, and make corrections if necessary.

2) In Phase 2, the programmer gives the command javac to compile the program.

Ex . javac Welcome.java

3) In phase 3, the program must first be placed in memory before it can be executed. This is done by the class loader, which takes the .class file (or files) containing the bytecodes and transfers it to memory.

4) Before the bytecodes in an application are executed by the java interpreter, they are verified by the bytecode verifierin Phase 4. This ensures that the bytecodes for class that are loaded form the internet (referred to as downloaded classes are valid and that they do not violate Java’s security restrictions

5) Finally in phase 5, the computer, under the control of its CPU, interprets the program one bytecode at a time. Thus performing the actions specified by the program.

Conclusion: We have successfully done the java program to identify the available memory in system.

Program:

import java.io.*; public class MemoryExp { public static void main(String[] args) {

try{

System.out.println("Total Memory"+Runtime.getRuntime().totalMemory()); System.out.println("Free Memory"+Runtime.getRuntime().freeMemory());}catch(Exception e){

} }}

class Pub{void a(){

Page 51: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

} }

class Pub1{void a(){} }

Output:

[student@localhost ~]$ javac MemoryExp.java

[student@localhost ~]$ java MemoryExp

Total Memory31195136

Free Memory30703360

Page 52: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

ASSIGNMENT NO:-16

Aim: Write a program to find number of CPU cores and CPU manufacturer.

Theory:

nproc - The tunable controls the absolute number of processes allowed on a system at any given time. Increasing it allows more processes and lowering it restricts the number of processes. You can determine that is too low when the message is seen in the message buffer. Use or to read the message buffer. This message indicates that an application was unable to create a new process. Setting too low can cause application failures due to an inability to fork new processes.

nproc - limits the number of processes allowed to exist simultaneously

--all print the number of installed processors

--ignore=Nif possible, exclude N processing units

--help display this help and exit

lscpu - lscpu gathers CPU architecture information from sysfs and /proc/cpuinfo. The command output can be optimized for parsing or for easy readability by humans. The information includes, for example, the number of CPUs, threads, cores, sockets, and Non-Uniform Memory Access (NUMA) nodes. There is also information about the CPU caches and cache sharing, family, model, bogo MIPS, byte order, and stepping.

lscpu - display information about the CPU architecture

-a, --allInclude lines for online and offline CPUs in the output (defaultfor -e). This option may only specified together with option -eor -p.

-b, --onlineLimit the output to online CPUs (default for -p). This optionmay only be specified together with option -e or -p.

Algorithm :

1. Initialize necessary variables & header files.2. We use system call "nproc=no of cores of CPU3. Now we use system call "lscpu=architecture of cpu"4. display5. output

Page 53: thirdyearengineering.weebly.comthirdyearengineering.weebly.com/.../osa_1_.docx  · Web view00:1c.4 PCI bridge: Intel Corporation 82801I (ICH9 Family) PCI Express Port 5 (rev 03)

Conclusion: We successfully done a program to find no of CPU cores and CPU architecture.

Program : #include <iostream>#include <stdlib.h>using namespace std;main(){ string name;string name1;cout<<"No. of CPU cores:\n";name = system ("nproc");cout<<name;cout<<"Information about CPU:\n";name1 = system ("lscpu");cout<<name1;}

Output :[student@localhost ~]$ gedit 1.cpp[student@localhost ~]$ g++ 1.cpp[student@localhost ~]$ ./a.outNo. of CPU cores:2Information about CPU:Architecture: i686CPU op-mode(s): 32-bit, 64-bitByte Order: Little EndianCPU(s): 2On-line CPU(s) list: 0,1Thread(s) per core: 1Core(s) per socket: 2Socket(s): 1Vendor ID: GenuineIntelCPU family: 6Model: 23Model name: Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHzStepping: 10CPU MHz: 1867.000BogoMIPS: 5852.45Virtualization: VT-xL1d cache: 32K