Outline
Download
1 / 18

Outline - PowerPoint PPT Presentation


  • 124 Views
  • Uploaded on

Outline. Unix Architecture Vi Fork Pthread. UNIX Architecture. System Calls and Library Functions. Application code. User process. C library functions. System calls. kernel. vi. vi. Vi editor have two modes Command mode Edit mode start vi : vi [filename]. Command mode.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Outline' - marcus


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Outline
Outline

  • Unix Architecture

  • Vi

  • Fork

  • Pthread



Outline

System Calls and Library Functions

Application code

User process

C library functions

System calls

kernel



Outline
vi

  • Vi editor have two modes

    • Command mode

    • Edit mode

  • start vi:

    vi [filename]

Command mode

Edit mode

Insert

Delete

Replace

Copy

.....

Command mode

Exit Edit mode

[Esc]


Edit mode
Edit mode

  • Insert

    • a Insert word after the cursor

    • i Insert word after the cursor

    • o Create a new line below the cursor

    • O Create a new line upon the cursor


Outline

  • Replace and Delete

    • x delete

    • ndw delete n word

    • ndd delete n line

    • r replace a word

  • Undo

    • U undo the changes in the same line

    • u undo the last action

  • Edit

    • nY or nyy copy n line

    • P or p paste

    • . redo the last action

    • / search


Command mode
Command Mode

  • :w save

  • :q exit

  • :q! exit and no save

  • :wq save and exit



Outline

  • The main purpose is to duplicate the process

  • The new process created by fork is called child process。

  • The return value in the child is 0,whereas the return value in the parent is the process ID of the new child。

  • It return only -1 when fork failed。



Thread
Thread

  • Light weight process

  • Share resources

  • Own private data

  • Synchronization


The pthread api
The Pthread API

  • Three major classes

    • Thread management

    • Mutex

    • Condition valuables

      All identifiers in the thread library begin with pthread_


Thread management
Thread Management

  • pthread_create(thread,attr,start_routine,arg)

  • pthread_exit (status)

  • pthread_attr_init (attr)

  • pthread_attr_destroy (attr)


Exit condition
Exit Condition

  • The thread returns from its starting routine (the main routine for the initial thread).

  • The thread makes a call to the pthread_exit subroutine.

  • The thread is canceled by another thread via the pthread_cancel routine.

  • The entire process is terminated due to a call to either the exec or exit subroutines.


Outline

#include<stdio.h>

#include<unistd.h>

int main()

{

pid_t pid;

pid = fork();

if(pid<0)

{

printf("fork failed");

exit(1);

}

else if(pid==0)

execlp("/bin/ls","ls","-al",NULL);

else

{

wait(NULL);

printf("Child Complete");

exit(0);

}

}


Outline

#include<pthread.h>

#include<stdio.h>

#define NUM_THREADS 5

void *PrintHello(void *threadid)

{

int tid;

tid = (int) threadid;

printf("Hello World! thread #%d\n", tid);

pthread_exit(NULL);

}

int main (int argc, char *argv[])

{

pthread_t threads[NUM_THREADS];

int rc , t;

for(t=0;t<NUM_THREADS;t++)

{

printf("In main: creating thread %d\n", t);

rc = pthread_create(&threads[t], NULL, PrintHello,(void *) t);

if(rc)

{

printf("ERROR; return code from pthread_create() is %d\n", rc);

exit(-1);

}

}

}