C언어와 유닉스 프로그램 언어가 같기에 질문을 드려봅니다.
의사양반
질문 제목 :C언어와 유닉스 프로그램 언어가 같기에 질문을 드려봅니다.
질문 요약 :3개의 프로그램을 하나로 합치고 싶어요질문 내용 :
말그대로 세개의 프로그램을 하나로 합치고 싶습니다. 소스는 있습니다. 합쳐서 하나로 만들어 주세요 ㅠ.ㅠ
쪽지로 보내주셔도 좋고 메일도 좋습니다. 그리고 합칠때 어떻게 합쳤는지도 알려주셨으면 좋겠습니다. ㅠ.ㅠ
1. fifo를 사용해 1:1대화가 가능하게
2. 타이머 설정을 해서 타임이 다되면 1/1대화가 종료 되게
3. 1/1프로그램의 프로세스 실행 시간 측정
이렇게 3가지 입니다.
제가 가지고 있는 소스는 1번 1/1대화는 완변하게 구현되었습니다. 2번은 그냥 타이머 설정 입니다. 3번은 단순히 times 함수를 이용해서 실행시간측정하는 소스입니다.
이 세가지를 연결 할수 있나요??? ㅠ.ㅠ
연결 하면 이렇게 구성이 되겠죠 1:1대화중에 타이머가 시간이 다되면 프로그램이 종료되고 해당 프로그램의 실행 시간을 측정도와주세요 ㅠ.ㅠ1번 대화가 가능하게 하는 소스 입니다.서버 소스
#include sys/types.h
#include sys/stat.h
#include fcntl.h
#include stdio.h
#include stdlib.h
#include unistd.h
main() {
int pd, pd1, n;
char msg[256];
if(mkfifo(./myfifo, 0666) == -1) {
perror(mkfifo);
exit(1);
}
if(mkfifo(./myfifo1, 0666) == -1) {
perror(mkfifo);
exit(1);
}
pd = open(./myfifo, O_WRONLY);
pd1 = open(./myfifo1, O_RDONLY);
if(pd == -1) {
perror(open);
exit(1);
}
while(1) {
printf(Server : );
gets(msg);
n = write(pd, msg, strlen(msg)+1);
if(n == -1) {
perror(write);
exit(1);
}
n = read(pd1, msg, 255);
printf(Client : %s\n, msg);
}
}
클라이언트 소스
#include sys/types.h
#include sys/stat.h
#include fcntl.h
돋움체#include stdio.h
#include stdlib.h
#include unistd.h
main() {
int pd, pd1, n;
char inmsg[256];
pd = open(./myfifo, O_RDONLY);
pd1 = open(./myfifo1, O_WRONLY);
if(pd == -1) {
perror(open);
exit(1);
}
printf(Client =====\n);
while(1) {
n=read(pd, inmsg, 255);
printf(Server : %s\n, inmsg);
printf(Client : );
gets(inmsg);
write(pd1, inmsg, strlen(inmsg)+1);
}
}
2번 타이머 설정 소스 입니다.
#include sys/time.h
#include unistd.h
#include signal.h
#include stdlib.h
#include stdio.h
void handler() {
printf(Timer Invoked..\n);
}
int main(void) {
struct itimerval it;
sigset(SIGALRM, handler);
it.it_value.tv_sec = 3;
it.it_value.tv_usec = 0;
it.it_interval.tv_sec = 2;
it.it_interval.tv_usec = 0;
if (setitimer(ITIMER_REAL, &it, (struct itimerval *)NULL) == -1) {
 sp; perror(setitimer);
exit(1);
}
while (1) {
if (getitimer(ITIMER_REAL, &it) == -1) {
perror(getitimer);
exit(1);
}
printf(%d sec, %d msec.\n, (int)it.it_value.tv_sec,
(int)it.it_value.tv_usec);
sleep(1);
}
return 0;
}
3. 1:1프로그램의 프로세스 실행 시간 측정 소스#include sys/types.h
#include sys/times.h
#include limits.h
#include unistd.h
#include stdlib.h
#include stdio.h
int main(void) {
int i;
time_t t;
struct tms mytms;
clock_t t1, t2;
if ((t1 = times(&mytms)) == -1) {
perror(times 1);
exit(1);
}
for (i = 0; i 999999; i++)
time(&t);
if ((t2 = times(&mytms)) == -1) {
perror(times 2);
exit(1);
}
printf(Real time : %.1f sec\n, (double)(t2 - t1) / CLK_TCK);
printf(User time : %.1f sec\n, (double)mytms.tms_utime / CLK_TCK);
printf(System time : %.1f sec\n, (double)mytms.tms_stime / CLK_TCK);
return 0;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2655440 | test파일이 안 되요. (2) | 리라 | 2024-05-19 |
2655416 | 고수님들 도움이 절실합니다. (2) | 세리 | 2024-05-19 |
2655361 | 엔터 입력받을때까지 기다리는 getchar (1) | 큰모음 | 2024-05-19 |
2655328 | 함수에서 포인터 (3) | 모아 | 2024-05-18 |
2655299 | 아이콘바꾸는법..? | 소 | 2024-05-18 |
2655271 | scanf 입력받으면 쭉 실행되는.. (5) | ComeOn | 2024-05-18 |
2655184 | 이 세개 프로그램좀 해결해주실.... 고수님들???? (3) | 말달리자 | 2024-05-17 |
2655129 | 다차원 배열 원소들 주소계산하는거 질문이요~ | 터전 | 2024-05-17 |
2655103 | AVRstudio MoveAxis. MoveLine 함수질문 | 앨버트 | 2024-05-16 |
2655072 | 콘솔창의 위치와 크기를 정하고 싶습니다. | 딥레드 | 2024-05-16 |
2655044 | 자료구조랑 online judge site에 대해서 질문있습니다... (1) | 뽀송뽀송 | 2024-05-16 |
2655016 | 별찍기 문제 중 이해안되는 부분이 있어요... | 도전중 | 2024-05-16 |
2654986 | 입력받은 성적을 배열에 저장하기 (3) | 안녕나야 | 2024-05-15 |
2654959 | ===========-이런거 미리 지정하는법 (1) | 김자영 | 2024-05-15 |
2654930 | 도와주십시요 ㅜㅜ 자료구조 ㅜㅜ | 도널드 | 2024-05-15 |
2654881 | PID 모듈 검색 부분 질문합니다 . | 이름없음 | 2024-05-14 |
2654850 | 조건에 만족하는 다음 수를 찾고 싶습니다. | 초엘 | 2024-05-14 |
2654790 | 두파일간 byte단위 txt파일 복사 中 | 슬찬 | 2024-05-14 |
2654768 | 사전만들기 입니다. | 여우By | 2024-05-13 |
2654716 | c언어 고수님들 답좀적어주세요 급합니다 ㅠㅠ | 한말글 | 2024-05-13 |