1 / 11

리눅스시스템프로그래밍 Ex)7-8

리눅스시스템프로그래밍 Ex)7-8. 2006242071 유승윤. 목차. 함수설명 소스분석 실행파 일. 함수설명. setjmp 스택환경을 env 에 보존하여 후에 longjmp 에 사용할 수 있게 한다 . 처음 호출 시에만 0 을 반환한다. 함수설명. longjmp 직전의 setjmp 를 호출하여 보존한 환경에 대응하는 env 인수를 사용하여 복원한다 . longjmp 는 setjmp 가 0 을 반환하게 할 수 없다. setjmp 는 현재 상태를 저장하고

Download Presentation

리눅스시스템프로그래밍 Ex)7-8

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 리눅스시스템프로그래밍Ex)7-8 2006242071 유승윤

  2. 목차 • 함수설명 • 소스분석 • 실행파일

  3. 함수설명 • setjmp 스택환경을env에 보존하여 후에 longjmp에 사용할 수 있게 한다. • 처음 호출 시에만 0을 반환한다.

  4. 함수설명 • longjmp 직전의 setjmp를 호출하여 보존한 환경에 대응하는 env인수를 사용하여 복원한다. • longjmp는 setjmp가 0을 반환하게 할 수 없다. setjmp는 현재 상태를 저장하고 longjmp이전 상태로 이동하는 역할을 하는 함수 goto() 함수와 비슷하다.

  5. Jmp_buf 프로그램 longjmp(jmp_buf ) setjmp(jmp_buf)

  6. 소스설명 #include<stdio.h> #include<stdlib.h> #include<signal.h> #include<setjmp.h> jmp_buf env1; main() { Intretcode, setjmp(); void ljmain(); signal(SIGINT,ljmain); retcode = setjmp(env1); if(retcode !=0) printf(“\n Before loop \n”); // longjmp로 분기했을때만 메시지를 출력한다 while(1) menu(); } jmp_buf는 상태를 저장하는 버퍼 구조체 setjmp함수에 의해 env1 에 현재 위치와 기타 정보가 저장 된다 인터럽트 시그널이 들어오면 ljmain루틴을 호출한다 setjmp현재 의 환경을 저장한다

  7. 소스설명 menu() { char resp[2]; prompt: printf(“cmd: ”); scanf(“%s”,resp); switch(resp[0]) { case ‘s’ : sfn(); break; case ‘t’ : tfn(); break; case ‘q’ : exit(0); default : printf(“?\n”); goto prompt; } } 메뉴를 입력받아 처리 루틴으로 분기한다

  8. 소스설명 void ljmain() { void longjmp(); signal(SIGINT,ljmain); printf(“\n INTERUPTED \n”); longjmp(env1,1); } sfn() { int i, i=0; for(i=0; ;i++) { printf(“%d \t”,i*i); sleep(1); if(++j %8 == 0) printf(“\n”); } } 인터럽트 신호가 수신되었을 때 실행되며, 신호를 재 설정하고 인터럽트 신호가 수신된 메시지를 출력한후 setjmp로 설정된 위치로 longjmp한다. For루프를 이용하여 정수의 값을 출력

  9. 소스설명 tfn() { long now, time(); char *ctime(); (void) time(&now); printf(“%s”,ctime(&now)); } Time과 ctime 함수를 호출하여 시간과 날짜를 출력

  10. 실행화면

  11. 인터럽트 실행으로 Signal(SIGINT, ljmain) 가 동작 jmp_bufenv1; 에저장되어 있는 위치로 이동

More Related