1 Posix API vs Windows API

Similar documents
How To Understand How A Process Works In Unix (Shell) (Shell Shell) (Program) (Unix) (For A Non-Program) And (Shell).Orgode) (Powerpoint) (Permanent) (Processes

System Security Fundamentals

CSI 402 Lecture 13 (Unix Process Related System Calls) 13 1 / 17

Operating Systems for Parallel Processing Assistent Lecturer Alecu Felician Economic Informatics Department Academy of Economic Studies Bucharest

Operating Systems and Networks

Shared Address Space Computing: Programming

OS: IPC I. Cooperating Processes. CIT 595 Spring Message Passing vs. Shared Memory. Message Passing: Unix Pipes

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Operating System Engineering: Fall 2005

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

System Calls Related to File Manipulation

Outline. Review. Inter process communication Signals Fork Pipes FIFO. Spotlights

RTI Monitoring Library Getting Started Guide

Hands-On UNIX Exercise:

Computer Systems II. Unix system calls. fork( ) wait( ) exit( ) How To Create New Processes? Creating and Executing Processes

Java Interview Questions and Answers

Libmonitor: A Tool for First-Party Monitoring

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Toasterkit - A NetBSD Rootkit. Anthony Martinez Thomas Bowen

Logging in Java Applications

OPERATING SYSTEM SERVICES

: provid.ir

3 - Lift with Monitors

Instrumentation for Linux Event Log Analysis

To Java SE 8, and Beyond (Plan B)

Introduction. dnotify

Program 5 - Processes and Signals (100 points)

Lecture 25 Systems Programming Process Control

Crash Course in Java

Operating Systems. 05. Threads. Paul Krzyzanowski. Rutgers University. Spring 2015

Introduction to: Computers & Programming: Input and Output (IO)

INTRODUCTION TO OBJECTIVE-C CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 12 09/29/2011

CS222: Systems Programming

Virtuozzo Virtualization SDK

Java Troubleshooting and Performance

Virtual Private Systems for FreeBSD

Implementing Rexx Handlers in NetRexx/Java/Rexx

µtasker Document FTP Client

AN INTRODUCTION TO UNIX

Recursion C++ DSP Toolkit Libraries DM6437 Cross Development

Getting Started with the Internet Communications Engine

How To Run A Test File Extension On A Rexx (Unix) On A Microsoft Linux (Amd64) (Orchestra) (For Windows) (

Permissions Mapping in the Isilon OneFS File System

Creating Database Tables in Microsoft SQL Server

CS 111 Classes I 1. Software Organization View to this point:

Linux/UNIX System Programming. POSIX Shared Memory. Michael Kerrisk, man7.org c February 2015

Source Code Management/Version Control

CS506 Web Design and Development Solved Online Quiz No. 01

Using NSM for Event Notification. Abstract. with DM3, R4, and Win32 Devices

Integrating Lustre with User Security Administration. LAD 15 // Chris Gouge // 2015 Sep

Specific Simple Network Management Tools

Writing a C-based Client/Server

Building a Multi-Threaded Web Server

HP-UX Essentials and Shell Programming Course Summary

Java Memory Model: Content

Configuring a Jetty Container for SESM Applications

Restraining Execution Environments

BF Survey Plus User Guide

The Linux Kernel: Process Management. CS591 (Spring 2001)

STORM. Simulation TOol for Real-time Multiprocessor scheduling. Designer Guide V3.3.1 September 2009

public static void main(string[] args) { System.out.println("hello, world"); } }

Lab 2 : Basic File Server. Introduction

Xcode Project Management Guide. (Legacy)

Getting Started with Telerik Data Access. Contents

CS420: Operating Systems OS Services & System Calls

Unix Scripts and Job Scheduling

Using vcenter Orchestrator AMQP Plug-in

An Implementation Of Multiprocessor Linux

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

C++ INTERVIEW QUESTIONS

Illustration 1: Diagram of program function and data flow

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

Threads Scheduling on Linux Operating Systems

Basics of I/O Streams and File I/O


CS1002: COMPUTER SCIENCE OO MODELLING & DESIGN: WEEK 5

CISC 181 Project 3 Designing Classes for Bank Accounts

Grundlagen der Betriebssystemprogrammierung

Jorix kernel: real-time scheduling

University of Pennsylvania Department of Electrical and Systems Engineering Digital Audio Basics

Tutorial: Getting Started

3.5. cmsg Developer s Guide. Data Acquisition Group JEFFERSON LAB. Version

Getting Started with STATISTICA Enterprise Programming

Chapter 6, The Operating System Machine Level

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Kiko> A personal job scheduler

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Using NFS v4 ACLs with Samba in a multiprotocol environment

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Project No. 2: Process Scheduling in Linux Submission due: April 28, 2014, 11:59pm

APACHE WEB SERVER. Andri Mirzal, PhD N

HP Operations Manager Software for Windows Integration Guide

COSC 6397 Big Data Analytics. Distributed File Systems (II) Edgar Gabriel Spring HDFS Basics

Process definition Concurrency Process status Process attributes PROCESES 1.3

Thread Synchronization and the Java Monitor

Windows Security. CSE497b - Spring 2007 Introduction Computer and Network Security Professor Jaeger.

Porting Lustre to Operating Systems other than Linux. Ken Hornstein US Naval Research Laboratory April 16, 2010

CIS 551 / TCOM 401 Computer and Network Security. Spring 2005 Lecture 4

Application Note. Running Applications Using Dialogic Global Call Software as Windows Services

Transcription:

1 Posix API vs Windows API 1.1 File I/O Using the Posix API, to open a file, you use open(filename, flags, more optional flags). If the O CREAT flag is passed, the file will be created if it doesnt exist. Additionally, the flags specify various flag attributes such as whether its read/write only, whether or not to block on open, whether to append on writes, and more. The optional flags are usually the permissions the file should on the filesystem when its opened. When using the Winodws API to open a file, you use CreateFile, and have to provide many more arguments to designate flags. The arguments for CreateFile, in generic terms, are filename, readable and/or writeable, shareable with other programs, security attributes, flag for whether to create or open an existing file, file attribute flags, and a flag for if its a template file. Posix Api : open( file.txt, O RDWR O CREAT, S IRWXU S IRWXG S IRWXO); Windows Api : CreateFile( file.txt, GENERIC READ GENERIC WRITE, 0, NULL, OPEN EXISTING, FILE ATTRIBUTE NORMAL, NULL); Both sets of code do the same thing, except the windows api does not allow for creating a file if it exists, or otherwise just opening it. That is what the O C REAT flag does in the Posix API s open function. Additionally, with the Posix API, most of the low level specifications for the file are not required, but are still easily implemented as flags. With the Windows API, many more of the implementation details are explicitly required and only assumed to be default of NULL or 0 are sent as parameters.

1.2 Threads To create a thread using the Posix API we have to use pthread create(pthread, pthreadattr, f unction, single arg). The thread data is populated when you provide an address for the pthread to be stored to, attr is the default thread attributes if NULL is provided, the function is a function of void return type, which only has a single argument: single arg. If more than one field need to be sent in though, a struct can be used as the single arg, giving it a way to hold multiple values when being passed around. To create a thread using the Windows API, we use the CreateThread(attrs, stack size, function, single arg, creation fla CreateThread doesn t have many more explicit parameters than pthread create, and both functions give a function and argument for the thread to use as parameters. PosixApi : pthread create(&thread id, N U LL, f unction pointer, f unction arg); W indowsapi : CreateT hread(n U LL, 0, f unction pointer, f unction arg, 0, &thread id); The differences between the two are CreateThread has explicit parameters for defining the state of the thread immediately after creation, such as running immediately, or being suspended, explicit thread attributes that define whether the thread can be inherited or not, and the initial size of the stack for a given thread. Overall though, both the Posix and Windows APIs operate in very similar manner for spawning threads. Using the Windows API, if the argument args is given a NULL value, and the arguments stack size and creation flags are given 0 values, the defaults are used and the functions from both the Posix and Windows APIs will perform the same.

1.3 Processes To use processes in the Posix API, we call fork() and assign the result to a variable. If the value is greater than 0, then we know we are in the parent process, and we now have the process id of the process we just spawned. If the value is equal to 0, we know we are in the child process, and now can assign the child to do some task. Lastly, if we get a -1, we know there was some sort of error we should handle. To create and run a process in the Windows API we use the CreateProcess function. Its parameters are application, command line code to execute, is process inheritable, is thread inheritable, inheritable handle, creation flags, parent environment, parent directory, startup info struct pointer, and process info struct pointer. PosixApi : int pid = fork(); if (pid > 0){ Do parent stuf f here else if (pid == 0) { Do child stuf f here W indowsapi : if(!createprocess(null,, NULL, NULL, FALSE,0, NULL, NULL,&startup info, &process info){ //Dochildstuf f As you can see, most of the parameters given to CreateProcess are defaulted to N U LL, F ALSE, or 0. This essentially boils the CreateProcess function down to providing process information in the &process i nfo struct, and retrieving it from there, whereas in the Posix API you would get the process id from the return value of f ork() and use functions to do things with those processes. CreateP rocess also only returns a Boolean, which states whether or not the process currently running is the child. The Windows and Posix APIs differ greatly when it comes to process initialization and handling. Like many other Windows API calls, the Windows API uses a much more explicit definition when declaring processes, but the differences are the Windows API doesnt do much with the process once its been created. There is a WaitForSingleObject method that is used for Windows API processes that waits for the process provided via the process information struct to finish running, whereas the in the Posix API we would use waitpid to wait for the process to finish before doing anything more.

1.4 Conclusion Overall, the Windows API seems to be much more verbose than the Posix API, but both seem to be very functionally similar. They each accomplish their tasks, mostly in similar ways, and the Windows API seems to have more items stored in structs, and give a lot more explicit definitions when using their functions. This would be nice, except as we can see, most of the time we dont need to explicitly say which security group for example that a thread belongs to. And if it is that important, we have the ability to make those adjustments after the initialization of the thread. Both the Posix and Windows APIs have their places, respectively on Unix and Windows systems and seem to fit the environments that come with them both there; Unix being more about simple use, and giving the ability to make low level modifications if needed, and Windows giving a ton of visible customizability up front, even if a bit overbearing.

1.5 Citations CreateFile: http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858(v=vs.85).aspx CreateThread: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682453(v=vs.85).aspx CreateProcess: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx CreateProcess Implementation: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682512(v=vs.85).aspx