[유닉스 시스템 프로그래밍] 5장 프로세스 정보
- 최초 등록일
- 2022.02.09
- 최종 저작일
- 2021.11
- 10페이지/ MS 워드
- 가격 1,000원
목차
1. 실습 예제
2. 연습 문제
본문내용
1. #include <unistd.h>
2. #include <stdio.h>
3. #include <stdlib.h>
4. #include <string.h>
5. #include <math.h>
7. int main(int argc, char *argv[]) {
8. // 인자를 입력하지 않으면 그냥 종료
9. if (argc <= 1) {
10. printf("인자를 입력하지 않으셨습니다.\n");
11. return 0;
12. }
14. char *input;
15. int pid, pgid, sid;
16. int transInt;
17. int inputLength;
18. int isError;
19. int i, j;
20. i = 1;
22. // 인자를 하나씩 읽어온다.
23. while ((input = argv[i]) != NULL) {
24. pid = 0;
25. inputLength = strlen(input) - 1;
27. // 예외 처리를 감안하여 인자를 1byte씩 파싱한다.
28. for (j = 0; inputLength >= 0; inputLength--) {
29. // char -> int
30. transInt = input[inputLength] - '0';
31. if (transInt < 0 || transInt > 9) {
32. isError = 1;
33. break;}
36. // pow해서 더하면 10진수가 된다.
37. pid = pid + transInt * pow(10, j);
38. j++;
39. }
41. printf("%d. PID가 %s인 프로세스의 PGID와 SID\n", i++, input);
42.
43. // 잘못된 PID 값에 대한 예외 처리
44. // 다음 인자로 넘긴다.
참고 자료
없음