SlideServe
Menu
Préférences
© SlideServe · v2026

Outline

marcus avatar
18 diapositives · 350 Views · Aug 20, 2014

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.

Outline - slide 1
01 / 18Outline
1 / 17

Télécharger la présentation

Outline
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Outline • Unix Architecture • Vi • Fork • Pthread

  2. UNIX Architecture

  3. System Calls and Library Functions Application code User process C library functions System calls kernel

  4. vi

  5. 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]

  6. 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

  7. 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

  8. Command Mode • :w save • :q exit • :q! exit and no save • :wq save and exit

  9. Fork

  10. 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。

  11. Pthread

  12. Thread • Light weight process • Share resources • Own private data • Synchronization

  13. The Pthread API • Three major classes • Thread management • Mutex • Condition valuables All identifiers in the thread library begin with pthread_

  14. Thread Management • pthread_create(thread,attr,start_routine,arg) • pthread_exit (status) • pthread_attr_init (attr) • pthread_attr_destroy (attr)

  15. 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.

  16. #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); } }

  17. #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); } } }