Abstraction or Arbitration

arbitration(R): distributing memory between multiple processes
abstruction(B): supporting different types of supeakers, interchangeable access of hard disk or SSD

Desktop, Embedded
microsoft windows, unix-based(mac os x(BSD), linux)
android, ios, Symbian

Abstractions
-process, thread, file, socket, memory page
Mechanism
-create, schedule

OS Element: memory management example
Abstractions: memory page
mechanism: allocate, map to a process
Policies: least recently used -LRU

Design princples
separation of mechanism 2 policy
-implement flexible mechanisms to support many polices
-e.g, LRU, LFU, random
Optimize for common case
– where will the os be used?
– what will the user want to execute on that machine?
– what are the workload requirements?

OS Protection Boundary
user/kernel protection boundary
privileged mode, kernel-level

user-kernel switch is supported by hardware
-trap instructions
-system call
open(file), send(socket), malloc(memory)
-signals

Operating System

What are operating systems?
Why are operating systems needed?
How are operating systems designed and implemented?

OS abstractions, mechanisms, and policies for:
-processes and process management
-threads and concurrency
-resource management: scheduling, memory management
-OS services for communication and I/O
-systems software for data center and cloud environments

Theory + Practice
sequence of programming projects
– threads, concurrency, and synchronization
– single-node Os mechanisms
inter-process communication, scheduling …
multi-node os mechanisms
– remote procedure calls(RPC),…
experimented design and evaluation
-> programming in C in Linux

Simple OS definition
– a special piece of software that…
abstract and arbitrates
the use of a computer system.

Direct operational resources
-control use of CPU, memory, peripheral devices…
Enforce working policies
Mitigate difficulty of complex tasks

Operating System(send/recive, socket, network, read/write file, storage)
CPU, MainMemory, Ethernet/Wifi Card, GPU, disk, usb
-hide hardware complexity
-resource management
-provide isolation < protection file system, device driver, scheduler

Working from the Command Line

Concepts to know
– read man page(man)
– navigate directories(cd, ls, pwd)
– move and copy files(mv, cp)
– adjust permissions or groups(chown, chmod)
– run executables(gcc, Cexecutables, or other tools)

# navigate to home dir
$ cd ~

# create main.c file
$ touch main.c

# edit main.c (write program)
$ nano main.c

# compile (and link) program
$ gcc main.c -o helloWorld

# run program
$ ./helloWorld

Makefiles concepts
– Targets and dependencies
– Comments(always useful)
– Variables(compiler, flags, etc.)
– Calling make from the command line

# specify the compiler
CC=gcc

# specify options for the compiler
CFLAGS=-c -Wall

all: hello

hello: main.o hello.o
	$(CC) main.o hello.o -o hello

main.o: main.cpp
	$(CC) $(CFLAGS) main.cpp

hello.o: hello.cpp
	$(CC) $(CFLAGS) hello.cpp

clean:
	rm -rf *o hello

UNIX Time or POSIX Time

#include <stdio.h>
#include <time.h>
int main()
{
	time_t sec;
	sec = time(NULL);

	printf("Number of hours since January 1, 1970 is %dId /n", sec/3600);
	return 0;
}

The following example shows the usage of rand() function.

#include 
#include 

int main()
{
	int i, n;
	time_t t;

	n = 5;

	/* Initializes random number generator */
	srand((unsigned) time(&t));

	/* Print 5 random numbers from 0 to 49 */
	for( i = 0; i < n; i++)
	{
		printf("%d\n", rand() % 50);
	}
	return(0);
}

The most important string functions are as follows:
strlen() Get length of a string.
strcat() Link together (concatenate) two strings.
strcmp() Compare two strings.
strchr() Find character in string.
strstr() Find string in string.
strlwr() Convert string to lowercase.
strupr() Convert string to uppercase.

#include <stdio.h>
#include <stdlib.h>

int main()
{
	char *t = "XXX";
	printf( "Length of <%s> is %d.\n", t, strlen( t ));
}

C programming

Concepts to know
-Structs, arrays, pointers, and reference types
-File I/O
-Use of command line parameters
-Pass-by-reference and pass-by-value
-Dynamic memory allocation using malloc()
-Use of C libraries

Helpful Skills related C
-Debugging programs
-Reading documentation
-Iterative design
-Good coding standards

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>

struct test_struct
{
	int val;
	struct test_struct *next;
}

struct test_struct *head = NULL;
struct test_struct *curr = NULL;

struct test_struct* create_list(int val)
{
	printf("\n creating list with headnode as [%d]\n", val);
	struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
	if(NULL == ptr)
	{
		printf("\n Node creation failed \n");
		return NULL;
	}
	ptr->val = val;
	ptr->next = NULL;

	head = curr = ptr;
	return ptr;
}

struct test_struct* add_to_list(int val, bool add_to_end)
{
	if(NULL == head)
	{
		return (create_list(val));
	}

	if(add_to_end)
		printf("\n Adding node to end of list with value [%d]\n",val);
	else
		printf("\n Adding node to beginning of list with value [%d]\n", val);

	struct test_struct *ptr = (struct test_struct*)malloc(sizeof(struct test_struct));
	if(NULL == ptr)
	{
		printf("\n Node creation failed \n");
		return NULL;
	}
	ptr->val = val;
	ptr->next = NULL;

	if(add_to_end)
	{
		curr->next = ptr;
		curr = ptr;
	}
	else
	{
		ptr->next = head;
		head = ptr;
	}
	return ptr;
}

struct test_struct* search_in_list(int val, struct test_struct **prev)
{
	struct test_struct *ptr = head;
	struct test_struct *tmp = NULL;
	bool found = false;

	printf("\n Searching the list for value [%d] \n", val);

	while(ptr !=NULL)
	{
		if(ptr->val == val)
		{
			found = true;
			break;
		}
		else
		{
			tmp = ptr;
			ptr = ptr->next;
		}	
	}

	if(true == found)
	{
		if(prev)
			*prev = tmp;
		return ptr;
	}
	else
	{
		return NULL;
	}
}

int delete_from_list(int val)
{
	struct test_struct *prev = NULL;
	struct test_struct *del = NULL;

	printf("\n Deleting value [%d] from list\n",val);

	del = search_in_list(val,&prev);
	if(del == NULL)
	{
		return -1;
	}
	else
	{
		if(prev != NULL)
			prev->next = del->next;

		if(del == curr)
		{
			curr = prev;
		}
		else if(del == head)
		{
			head = del->next;
		}
	}
	free(del);
	del = NULL;

	return 0;
}	
void print_list(void)
{
	struct test_struct *ptr = head;

	printf("\n ----Printing list Start---- \n");
	while(ptr != NULL)
	{
		printf("\n [%d] \n",ptr->val);
		ptr = ptr->next;
	}
	printf("\n -------Printing list End ------ \n");
	return;
}

int main(void)
{
	int i = 0, ret = 0;
	struct test_struct *ptr = NULL;

	print_list();

	for(i = 5; i<10; i++)
			add_to_list(i,true);

	print_list();
	for(i =4; i>0; i--)
		add_to_list(i,false);

	print_list();

	for(i = 1; i<10; i += 4)
	{
		ptr = search_in_list(i, NULL);
		if(NULL == ptr)
		{
			printf("\n Search &#91;val = %d&#93; failed, no such element found\n",i);
		}
		else
		{
			printf("\n Search passed &#91;val = %d&#93;\n", ptr->val);
		}

		print_list();
		ret = delete_from_list(i);
		if(ret != 0)
		{
			printf("\n delete [val = %d] failed, no such element found\n",i);
		}
		else
		{
			printf("\n delete [val = %d] passed \n", i);
		}
		print_list();
	}
	return 0;
}

LEAP/SLERP

Vector3.Lerp Documentation:
https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html

Quaternion.SLERP Documentation:
https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html

Methods and Debugging

Debugging

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
	public void GoToScene(){
		Debug.log("My method was called!")	
	}
}

Scene Changing

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class NewBehaviourScript : MonoBehaviour {
	public void GoToScene(){
		Debug.log("My method was called!");
		SceneManager.LoadScene("00-FallingCoconut");
	}
}

The Variables

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;

public class NewBehaviourScript : MonoBehaviour {
	public void GoToScene(string sceneName){
		Debug.log("My method was called!");
		SceneManager.LoadScene("sceneName");
	}
}

Prefabs

-Allow you to store a GameObject, all of its components, and settings in a file on your hard disk
-Think of prefabs as a “plan” that Unity follows to create certain GameObjects

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	public GameObject objectToCreate;

	// Use this for initialization
	void Start () {
		// make an object
		// Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity);
		for (int i = 0; i < 50; i++){
			// Object.Instantiate(objectToCreate, new Vector3(i,4,6), Outereign.identity);
			GameObject newSeaqull = (GameObject)Object.Instantiate(objectToCreate, new Vector3(1, 8, 0), Quatereign.identity);
			Render objectRenderer = newSeaqull.GetComponentInChildren<Renderer>();
			objectRenderer.material.color = Color.whilte * Random.value;
		}
	}
	
	// Update is called once per frame
	void Update () {

	}
}

new Vector3(x, y, z)

-This is how specify positions in 3D space
-Creates a new Vector3 object
-First number is the x coordinate
-Second number is the y coordinate
-Third number is the z coordinate

Quaternions
-How Unity handles 3D rotations
-Better for simulations than Euler angles
-Unity handles all the complicated math

Comments
-Great way to write programming notes to yourself and others
-Also useful for saving code for later reference

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	public GameObject objectToCreate;

	// Use this for initialization
	void Start () {
		// make an object
		// Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity);
		for (int i = 0; i < 1000; i++){
			Object.Instantiate(objectToCreate, new Vector3(i,4,6), Outereign.identity);
		}
	}
	
	// Update is called once per frame
	void Update () {

	}
}

Creating Objects using Code

Creating Objects using Code
– This is called Instantiating
– You are creating a new instance of something

References
References allow to drag-and-drop objects into code using the Unity Editor.

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

	public GameObject objectToCreate;

	// Use this for initialization
	void Start () {
		// make an object
		Object.Instantiate(objectToCreate, new Vector3(2,4,6), Outereign.identity);
	}
	
	// Update is called once per frame
	void Update () {

	}
}