Sie sind auf Seite 1von 8

Career Companion

Course Code : MCS-041 Course Title : Operating Systems Last Dates for Submission : 15th October, 2013 (For July 2013 Session) 15th April, 2014 (For January 2014 Session)

Question: 2 #include<stdio.h> #include<stdlib.h> #include<unistd.h> #include<pthread.h> #include<errno.h> #include<sys/ipc.h> #include<semaphore.h> #define N 5 time_t end_time;/*end time*/ sem_t mutex,customers,barbers;/*Three semaphors*/ int count=0;/*The number of customers waiting for haircuts*/ void barber(void *arg); void customer(void *arg); int main(int argc,char *argv[]) { pthread_t id1,id2; int status=0; end_time=time(NULL)+20;/*Barber Shop Hours is 20s*/ /*Semaphore initialization*/ sem_init(&mutex,0,1); sem_init(&customers,0,0); sem_init(&barbers,0,1); /*Barber_thread initialization*/ status=pthread_create(&id1,NULL,(void *)barber,NULL); if(status!=0) perror("create barbers is failure!\n"); /*Customer_thread initialization*/ status=pthread_create(&id2,NULL,(void *)customer,NULL); if(status!=0) perror("create customers is failure!\n"); /*Customer_thread first blocked*/ pthread_join(id2,NULL); pthread_join(id1,NULL);

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

exit(0); } void barber(void *arg)/*Barber Process*/ { while(time(NULL)<end_time || count>0) { sem_wait(&customers);/*P(customers)*/ sem_wait(&mutex);/*P(mutex)*/ count--; printf("Barber:cut hair,count is:%d.\n",count); sem_post(&mutex);/*V(mutex)*/ sem_post(&barbers);/*V(barbers)*/ sleep(3); } } void customer(void *arg)/*Customers Process*/ { while(time(NULL)<end_time) { sem_wait(&mutex);/*P(mutex)*/ if(count<N) { count++; printf("Customer:add count,count is:%d\n",count); sem_post(&mutex);/*V(mutex)*/ sem_post(&customer);/*V(customers)*/ sem_wait(&barbers);/*P(barbers)*/ } else /*V(mutex)*/ /*If the number is full of customers,just put the mutex lock let go*/ sem_post(&mutex); sleep(1); } } Question 4: Ubuntu is an operating system based on the Linux kernel and the Linux distribution Debian, with Unity as its default desktop environment. It is distributed as free and open source software. Development of Ubuntu is led by Canonical Ltd.,[15] a company based in the Isle of Man and owned by South African entrepreneur Mark Shuttleworth. Features:

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

Ubuntu is composed of many software packages, the majority of which are distributed under a free software license. The main license used is the GNU General Public License (GNU GPL) which, along with the GNU Lesser General Public License (GNU LGPL), explicitly declares that users are free to run, copy, distribute, study, change, develop and improve the software. On the other hand, there is also proprietary software available that can run on Ubuntu. The Ubiquity installer allows Ubuntu to be installed to the hard disk from within the Live CD environment, without the need for restarting the computer prior to installation. Beginning with 5.04, UTF-8 became the default character encoding,[19] which allows for support of a variety of non-Roman scripts. To provide a more secure environment, the sudo tool is used to assign temporary privileges for performing administrative tasks, allowing the root account to remain locked, and preventing inexperienced users from inadvertently making catastrophic system changes or opening security holes.[20] PolicyKit is also being widely implemented into the desktop to further harden the system through the principle of least privilege. Ubuntu Desktop includes a graphical desktop environment. In versions prior to 11.04 the default GUI was GNOME Panel but it was dropped in favor of Unity, a graphical interface Canonical first developed for the Ubuntu Netbook Edition.[21] Ubuntu comes installed with a wide range of software that includes LibreOffice, Firefox, Thunderbird, Empathy, Transmission, and several lightweight games (such as Sudoku and chess). Additional software that is not installed by default (including software that used to be in the default installation such as Evolution, GIMP, Pidgin, and Synaptic) can be downloaded and installed using the Ubuntu Software Center[22] or other apt-based package management tools. Programs in the Software Center are mostly free, but there are also priced products, including applications and magazines. Ubuntu can close its own network ports using its own firewalls software. End-users can install Gufw (GUI for Uncomplicated Firewall) and keep it enabled.[23] GNOME (the former default desktop) offers support for more than 46 languages.[24] Ubuntu can also run many programs designed for Microsoft Windows (such as Microsoft Office), through Wine or using a Virtual Machine (such as VMware Workstation or VirtualBox). Ubuntu compiles their packages using gcc features such as PIE and Buffer overflow protection to harden their software.[25] These extra features greatly increase security at the performance expense of 1% in 32 bit and 0.01% in 64 bit.[26]

Process scheduling As far as the process management is concerned, UBUNTU Linux11.04 has preemptive kernel and supports Symmetric Multiprocessing (SMP).

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

There are two spaces that we identify in process circle. The kernel space and the user space. The process management takes place in the kernel space. Components of the UBUNTU/Linux system As every Linux system, UBUNTU is composed of three main parts of code.

The kernel It is the heart of the OS. It is responsible for mainting all the important

abstractions of the operating system, including such things as virtual memory and processes (Operating Systems Concepts, p. 807)

System libraries

They include sets of fucntions that do not need kernel priviledges in order applications to interact with the kernel.

System utilies

They include programs that perform individual management tasks, eg initialize, configure aspects of the system. In addition there are the so called deamons, that may run permanently, handling such tasks as responding to incoming network connections, accepting logon requests from terminal and updating log files Processes and threads are not that different for linux. Both fork() and exec() are used to create processes. Threads are created by the clone() system call. Clone() creates a child process allowing it to use shared information with the parent process by sets of flags that are passed to it. This how a thead is described in other Operating Systems. Exec() is the system call used to run new program whereas fork() is the system call to create a new process. In general it can be said that fork() is similar to clone() when no flags are passed to the new process.

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

UBUNTU Linux 11.04 have two seperate process-scheduling algorithms. One is time-sharing for fair, preemptive scheduling among multiple processes; the other is designed fo real-time tasks. Real-time algorithms are also supported, for special time-critical applications that need precise control over the way in which runnable processes are selected for execution. The time sharing algorithms are three.

SCHED_OTHER SCHED_BATCH SCHED_IDLE

For the time sharing algorithms, the standard Round-Robin method is used. It is a First-Comes-First-Served (FCFS) method, but also assingning a time quanta for each process, creating a loop ending with the init() system call, which is the parent of all processes. Kernel synchronization Tasks may try to access the same internal data structures. Since UBUNTU Linux are preemptive, if another task with higher priority is ready to use CPU time, the running task will be preempted even if running in kernel. In order to lock the kernel, UBUNTU provides spinlocks and semaphores.For Symmetric Multiprocessing machines, spinslocks are the fundamental mechanism. This cannot happen in single processor machines since there is only one CPU time and locking for short periods, which is what spinslocks do, would have high impact to the system performance. Instead of spinlocks, in single processor machines, the preemptive ability is enabled and disabled instead. The most important aspect in preemptive mechanism is what happens with interrups. IN UBUNTU the interrupts are prioritized and seperated into two parts. The top-half one and the bottom-half one. An interrupt form the first class can interrupt one form the second class, but cannot interrupt another of the same class. Protection

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

Ubuntu Linux has a built-in firewall called netfilter. Ubuntu security model is closely related to typical Unix security mechanisms It can be classified in two groups:

Authentication, and Access Authentication control

Authentication is making sure that only authorised people can access the system, proving their identity. Ubuntu uses the pluggable authentication modules (PAM) system, which a mechamism on a shared library making it possible to be used by any system component. (Operating system Concepts, p.840-841) Access control is providing a mechanism to check whether a user has the right to access a certain object and preventing access if required. In Ubuntu there are three categories of users.

User/owner Group The rest

A user is identified by the UID. We can also determine privileges for a group of user, who will be identify by the GID. Root is a special type of user. It is the equivalent of administrator and has full system access. There are 3 types for permissions in file/folders.

Execute (x) Write (w) Read only (r)

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

The implementation of security scheme in Linux is directly linked, on the physical layer, with the file system. The file system must be able to store the privileges for users and groups in each file. The speciality of Ubuntu, in the implementation of security policy of linux, is that it allows normal users to borrow root privileges. Ubuntu encourages a simple user to log in with the minimum privileges required. However, when required, eg to access system tools, files or perform administrative actions in general, he does not have to log out and relogin. A pop up window shows up and the root password is required to proceed, otherwise no action is taken. In terminal, the $ symbol determine a simple user and # character determines that superuser is logged in. Encyption Ubuntu offers the ability to encypt the /home folder so that only the current user and the root will have access to the personal files. Additionally the ability to encrypt a file or folder is also available. PGP protocol is used to do so and the keys are 2024-bit long. (Ubuntu Pocket Guide and Reference, p126-128) Keyring Keyring a repository for passwords. It is there to help us with password control. Since a simple user may have several passwords for several objects (browsers, sites etc), keying is there to gather all of them. When an application needs to access the keyring to get the correct password, then a popup window appears to enter the default keyring password. It is a helpful attribute of the OS. Security tools Graphical Security tools can be found in the Control center, under the Other and System category.

If you like my work and want to appreciate me send thanks to 9429 007 439

Career Companion

User and Groups tool, allow us to create users and groups, assigning them rights. Passwords and Encryptions keys is where keying preferences are stored and encryption options can be found.

Terminal Below are listed some basic commands to manipulate users and permissions through the terminal - sudo adduser --home /home/john john command creates a user with the name john and also creates the Home folder - deluser --remove-all-files, command will delete the user john as well as all the file sand the Home folder - sudo adduser john accounts, will add john to the accounts group - sudo delgroup accounts, will remove accounts group - sudo deluser john accounts, will remove john from the accounts group - ls -la, will list all files and folder in a folder with permissions and ownerships

chmod {options} filename, command to change ownership and permissions in files and folders

Remaining answers of questions will be uploaded soon stay checked.

If you like my work and want to appreciate me send thanks to 9429 007 439

Das könnte Ihnen auch gefallen