실습 목적difftime()와 clock()을 이용해서 두가지 정렬 함수의 전체수행시간과 실제수행 시간을컴파일 후 반복 실행을 통한 비교실습 개요difftime(sec,fir) ,(end-start)/CLOCKS_PER_SEC 다음 2개의 time.h에 이미 정의된함수와 변수를 사용해서 정렬을 목적으로 하는 루틴을 수행 한 전 후에 시간을 측정하여 2가지 함수의 차이점과 실제 실행시간의 차이점을 이해한다#include #include #include #define Max 5000#define SWAP(a, b, c) ((c)=(a), (a)=(b), (b)=(c))//SWAPint data[Max];void makedata();void bubble();int main(void){int i;clock_t start,end;time_t fir, sec;makedata();// for(i = 1; i
실습 목적IPC에 대한 전반적인 이해와 이와 관련된 메시지 큐의 작동 원리를 이해하고ipsc,ipcrm 에 대한 사용법을 통한 실습을 한다.실습 개요부모 프로세스에서 자신만의 식별자를 지닌 메시지 큐를 새로 하나 만들고이 메지시 큐에 임의의 숫자를 1000개 저장한다. 자식 프로세스에서 이 메시지큐를 읽어서 숫자에 대한 합과 그 평균 값을 구한다. 메시지 큐의 생성 여부는ipcs명령어로 확인 할 수 있으며 아래에 프로그램 내에서는 자식 프로세스의 접근이후 삭제해 준다.프로그램 소스#include #include #include #include #include #include #define FIFO 0L#define MAX_SEND_SZ 30#define DONE 99L#define MAX_LIMIT 1000void pro_exe(void);static struct{long mtype;int mtextnum;}buf;key_t key;int mid,rtn;int main(void){time_t jjs; //임의의 수를 생성해 줄 때 좀도 랜덤한 숫자가 들어가도록 하기위해int i,res; //현재 시간 값을 이용//새로운 ipc식별자를 만들기 위한 부분if((key=ftok(".",'a'))==-1) {perror("Can't form key");exit(1);}//만들어준 식별자 값으로 새로운 메시지 큐를 만들어 줍니다.mid=msgget(key, IPC_CREAT|0660); //IPC_CREAT모드로 새로 생성if(mid==-1){ //메시지큐 생성 실패시 에러 메시지perror("Sender can not make msg queue!");exit(2);}buf.mtype=1L;printf("Make num-array.....");for(i=0; i
csh (C shell)이란?C 언어와 비슷한 syntax를 가진 명령 해석기 (command interpreter)csh에는 interactive operation과 noninteractive operation이 있다.interactive operation: 프롬프트가 튀어나와서 사용자의 명령을 기다리는 형태noninteractive operation: 스크립트 (script) 파일이나 명령행 (command line)에서 주어진 argument들을 프롬프트 없이 알아서 수행oFile name completionfilec 가 set 되어 있으면 부분적으로 타이핑된 파일 이름 끝에 EOF character (Ctrl-D) 가 붙으면 자동적으로 나머지를 완성해준다. 같은 글자로 시작하는 파일이 여러 개 있으면 그 리스트를 보여준다. (tcsh 에서는 tab 으로도 가능)~ (tilde) 가 앞서면 파일 이름이 아니라 user directory 를 찾는다.nex) cd ~ys [Ctrl-D]yskim yskwon ysleeoLexical structure기본적으로 shell 은 tab 이나 space 로 단어를 구분한다. 예외적인 구분자는 아래와 같다.n&, |, ;, , (, and )n 뒤에 위의 글자를 쓰면 그냥 의미없는 문자로 취급다음으로 둘러싸인 문자열은 한 단어로 취급 (matched pairs)n`this is a token`n'this is a token'n"this is a token"oCommand line parsingcommand1 | command2: pipelining. command1 의 standard output 이 command2 로 redirection 된다.command1 |& command2: pipelining. command1 의 standard output 과 standard error 가 command2 로 redirection 된다.command1 ; command2: command1 과 command2 가 순서대로 수행된다.command1 && command2: command1 가 성공적으로 수행되면 command2 가 수행된다.command1 || command2: command1 이 실패하면 command2 가 수행된다.command &: command 가 background 에서 수행된다.Event Designatorsn! : history substitution 의 시작을 알림n!! : 바로 전 command 를 가리킴n!n : n 번 history 의 command 수행n!-n : current line n 번째 command 수행n!str : str 로 시작하는 history 상의 command 중 가장 최근 것으로 치환해준다.ex) hisotry 에 design_analyzer 라는 command 가 있으면 !des [enter] 하면 바로 design_analyzer 가 다시 입력된다.n!{command} additional: 위와 같으나 추가 명령을 뒤에 붙임ex) !des f script : design_analyzer f script 와 같은 효과n!?str? : str 이 포함되어 있는 가장 최근 것으로 치환n!?str? additional: 위와 같으나 추가 명령을 뒤에 붙임^previous_word^replacement^: 바로 전의 command line을 previous_word를 replacement로 치환하여 실행한다.ex) % vi cshell.txt% ^cshell^ksh^vi ksh.txtn 또다른 방법:!:s/previous_word/replacement!6:s/previous_word/replacement 이건 뭘까?oWord Designators: (colon) 은 event specification 과 word designator 를 구분해준다. ( 앞에서 본 바와 같이 )BUT! word designator 가 ^, $, *, - or % 로 시작하면 colon 은 생략해도 된다. 만약에 바로 전의 command 에 대하여 word designate 를 하려 하면 두번째 ! 는 생략해도 된다. ( 앞에서 본 바와 같이 )Word designatorsnex) %gcc g prgm.c o prgmn#: the entire command line typed so far.ex) %vi !#vi vin0: the first input word (command)ex) %man !:0man gccnn: the n'th argumentex) %vi !:2vi prgm.cn^: the first argument, that is, 1.ex) %gcc !^ com1.cgcc g com1.cn$: the last argumentex) % !$prgmnx-y: A range of wrods; -y abbreviates 0-yn*: All the arguments, or a null value if there is just one word in eventex) % vi prgm.c% gcc !* -o prgmgcc prgm.c o prgmnx*: Abbreviates x-$nx-: Like x* but omitting word $.oModifierscommand 다음에 colon 을 붙이고 다음과 같은 modifier 를 추가할 수있다.modifersnh: pathname 에서 끝부분을 없애주고 head 만 남긴다.ex) % vi ../../arm/iss.h% cd !$:hcd ../../armnr: '.xxx' 형태의 suffix 를 없애주고 base name 만 남긴다.ex) % vi cshell.txt% vi !$:rvi cshellne: 위와 반대ex) % vi cshell.txt% vi ksh.!$:evi ksh.txtns/l/r: l을 r로 바꾸어준다.ex) % vi cshell.txt% vi!$:s/txt/textvi cshell.textnt: Leading pathname component 를 없애고 끝부분만 남긴다.ex) % ls ../../arm/ipc/ipctest.c/home/yslee/work/arm/ipc/ipctest.c% vi !$:tvi ipctest.cn&: repeat the previous substitutionnp: command 를 찍기만 하고 수행하지는 않는다.nq: Quote the substituted words, escaping further substitutions.ex) % ls ../../arm/ipc/ipctest.c% echo !!:qecho ../../arm/ipc/ipctest.c../../arm/ipc/ipctest.coAliases이 문장을 저 단어로 대체한다.nex)% alias rm 'rm i' 이렇게 하면 rm 이라고 칠 때마다 rm i 가 수행된다.% rm 하면 alias 된 문장이 수행되지 않고 그냥 원조 rm 이 수행된다.% alias [enter] 하면 현재 alias 되어 있는 모든 항목들이 표시된다.% alias word [enter] 하면 word 가 무엇으로 alias 되어 있는지 표시된다.% unalias word[enter] 하면 word 에 걸린 alias 가 풀린다.oI/O Redirectionstandard output, standard error, standard input 의 방향을 바꿀 (redirect) 수 있다.Redirection metacharactersn& >&!Redirect standard output to a fileex) % man csh >? shell.txtn>> >>& >>! >>&!Append the standard output to a fileex) % man ksh >> shell.txtoExpression and operators( ) : grouping~ : one's complement! : logical negation* / % : 곱셈, 나눗셈, 나머지+ - : 덧셈 뺄셈< >> : bitwise left shift, rigth shift< >