Develop
2003.04.23 10:55

[linux] 프로세스 관련 시스템콜

Views 7827 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
system ( ) 함수: 쉘 명령어를 실행시킨다.

예제: system.c
     1  #include <stdlib.h>
     2
     3  main() {
     4      system("/usr/bin/ls  -l");
     5  }

#35 hyundai1:/export/home0/oracle/sql/sql00/c% a.out
총 14
-rwxr-xr-x   1 sql00    sql         5444 11월  6일  20:00 a.out
-rw-r--r--   1 sql00    sql           60 11월  6일  20:00 system.c


--------------------------------------------------------------------------------

execl ( ) 함수: 프로그램을 실행시킨다.

예제: execl.c
     1  main() {
     2      int pid;
     3      int status;
     4
     5      pid = fork();
     6      if(pid > 0) {
     7          wait(&status);
     8      } else if(pid == 0) {
     9          execl("/usr/bin/ls", "ls", "-l", 0);
    10      } else {
    11          printf("fork error.n");
    12      }
    13  }

#97 hyundai1:/export/home0/oracle/sql/sql00/c% a.out
총 26
-rwxr-xr-x   1 sql00    sql         5736 11월  6일  21:11 a.out
-rw-r--r--   1 sql00    sql          185 11월  6일  21:11 execl.c
-rw-r--r--   1 sql00    sql           69 11월  6일  20:03 fork.c
-rw-r--r--   1 sql00    sql          196 11월  6일  21:03 fork2.c
-rw-r--r--   1 sql00    sql          213 11월  6일  21:03 fork3.c
-rw-r--r--   1 sql00    sql         1736 11월  6일  21:08 process.html
-rw-r--r--   1 sql00    sql           60 11월  6일  20:00 system.c
<xmp>


--------------------------------------------------------------------------------

fork ( ) 함수: 새로운 프로세스를 생성한다.

예제: fork1.c
     1  main() {
     2      int pid;
     3
     4      pid =  fork();
     5      printf("my pid = %dn", pid);
     6  }

#43 hyundai1:/export/home0/oracle/sql/sql00/c% a.out
my pid = 0
my pid = 9015

예제: fork2.c
     1  main() {
     2      int pid;
     3
     4      pid =  fork();
     5      if(pid > 0) {
     6          printf("I am parent.n");
     7      } else if(pid == 0) {
     8          sleep(1);
     9          printf("I am child.n");
    10      } else {
    11          printf("fork error.n");
    12      }
    13  }

#75 hyundai1:/export/home0/oracle/sql/sql00/c% a.out
I am parent.
#76 hyundai1:/export/home0/oracle/sql/sql00/c% I am child.


--------------------------------------------------------------------------------

wait ( ) 함수: 부모 프로세스가 자식 프로세스가 종료될 때까지 기다린다.

예제: fork3.c
     1  main() {
     2      int pid;
     3      int status;
     4
     5      pid =  fork();
     6      if(pid > 0) {
     7          printf("I am parent.n");
     8          wait(&status);
     9      } else if(pid == 0) {
    10          sleep(2);
    11          printf("I am child.n");
    12      } else {
    13          printf("fork error.n");
    14      }
    15  }

#87 hyundai1:/export/home0/oracle/sql/sql00/c% a.out
I am parent.
I am child.


--------------------------------------------------------------------------------

atexit ( ) 함수: 프로그램이 종료되기 전에 atexit에 등록된 함수가 수행된다.

사용법
        #include 
        int atexit(void (*func)(void));

예제: atexit.c
     1  #include <stdio.h>
     2  #include <stdlib.h>
     3
     4  void cleanup() {
     5      printf("Clean up before exit.n");
     6  }
     7
     8  main() {
     9      atexit(cleanup);
    10      printf("Hello World !!n");
    11  }

#19 enterprise:/data1/student/c9844000% a.out
Hello World !!
Clean up before exit.

?

  1. [c] 문자열 정렬 함수 qsort()

    Date2003.04.23 CategoryDevelop Byhooni Views8228
    Read More
  2. [c] OpenGL 임시로 여기 올림..

    Date2003.04.23 CategoryDevelop Byhooni Views10324
    Read More
  3. [c] 정수를 2진수로 변환 (재귀,비트연산)

    Date2003.04.23 CategoryDevelop Byhooni Views7581
    Read More
  4. [c] OpenGL 관측점 이동

    Date2003.04.23 CategoryDevelop Byhooni Views7609
    Read More
  5. [c] 팩토리얼 서버/클라이언트..

    Date2003.04.23 CategoryDevelop Byhooni Views17286
    Read More
  6. [c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..)

    Date2003.04.23 CategoryDevelop Byhooni Views7246
    Read More
  7. [c] 라인수 입력받아 마름모꼴 출력하기..

    Date2003.04.23 CategoryDevelop Byhooni Views6868
    Read More
  8. [c] 단기과정[01/06] sizeof, 실수표현, 메모리, 연산자

    Date2003.04.23 CategoryDevelop Byhooni Views6927
    Read More
  9. [c] 단기과정[01/07] 제어문, 피보나치수열

    Date2003.04.23 CategoryDevelop Byhooni Views7410
    Read More
  10. [c] 단기과정[01/08] 배열, 포인터

    Date2003.04.23 CategoryDevelop Byhooni Views7223
    Read More
  11. [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터

    Date2003.04.23 CategoryDevelop Byhooni Views7770
    Read More
  12. [c] 단기과정[01/08] 과제.. 파스칼 삼각형

    Date2003.04.23 CategoryDevelop Byhooni Views7256
    Read More
  13. [c] 단기과정[01/10] 과제.. swap(any data, ..)

    Date2003.04.23 CategoryDevelop Byhooni Views6904
    Read More
  14. [c] 단기과정[01/14] 파일 입출력

    Date2003.04.23 CategoryDevelop Byhooni Views6821
    Read More
  15. [c] 단기과정[01/14] 피보나치, 파스칼.. 파일입출력

    Date2003.04.23 CategoryDevelop Byhooni Views7081
    Read More
  16. [c] 단기과정[01/15] 피보나치, 파스칼.. 링크리스트

    Date2003.04.23 CategoryDevelop Byhooni Views7234
    Read More
Board Pagination Prev 1 ... 6 7 8 9 10 ... 53 Next
/ 53