20130507

학교 실습/HCI 2013. 5. 7. 10:13

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int pid1,pid2,pid3;
    printf("자기 자신의 프로세스 : %d\n",getpid());
    pid1=fork();
    if(pid1==0)
    {
        printf("부모 프로세스 : %d, 자기 자신의 프로세스 : %d\n",getppid(),getpid());
        pid2=fork();
        if(pid2==0)
        {
            printf("부모 프로세스 : %d, 자기 자신의 프로세스 : %d\n",getppid(),getpid());
            pid3=fork();
            if(pid3==0)
            {
                printf("부모 프로세스 : %d, 자기 자신의 프로세스 : %d\n",getppid(),getpid());
            }
            else
            {
                wait();
            }
           
        }
        else
        {
            wait();
        }
    }
    else
    {
        wait();
    }
}
/////////////////////////////////////////////////////////////////////////////////

#include <stdio.h>
#include <stdlib.h>

/* 부모 프로세스가 자식 프로세스를 생성하고 끝나기를 기다린다*/

int main(){
 int pid, child, status;
 printf("[%d] 부모 프로세스 시작 \n", getpid());
 pid= fork();
 if(pid == 0){
  printf("[%d] 자식 프로세스 시작 \n",getpid());
  sleep(10);
  exit(1);
 }
 child = wait(&status);
 printf("[%d] 자식 프로세스 %d 종료 \n",getpid(), child);
 printf("\t 종료코드 %d\n", status>>8);
}

 

'학교 실습 > HCI' 카테고리의 다른 글

130513  (0) 2013.05.13
20130508  (0) 2013.05.08
HCI 20130501  (0) 2013.05.01
HCI 20130429  (0) 2013.04.29
TVTEST  (0) 2013.04.17

HCI 20130501

학교 실습/HCI 2013. 5. 1. 14:58

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package cartest2;


class Car {


    int fuelecon;

    String Diesel;

    String Hybrid;

    String gasoline;

    String fuelType;

    String color; // 색상

    String gearType; // 변속기 종류 - auto(자동), manual(수동)

    int door; // 문의 개수

////////////////////////////////////////////////////////////////////////


    Car(String color, String gearType, int door, int fuelecon, String fuelType) {

        this.color = color;

        this.gearType = gearType;

        this.door = door;

        this.fuelecon = fuelecon;

        this.fuelType = fuelType;

    }


    Car() {

        this("white", "matic", 6, 20, "gasoline");

    }

    Car(int door, int fuelecon){

        this("white","auto",door,fuelecon,"가솔린");

    }

}


class CarTest2 {


    public static void main(String[] args) {

        Car c1 = new Car();

        System.out.println("c1의 color=" + c1.color + ", gearType=" + c1.gearType + ", door=" + c1.door+ ", fuelecon=" + c1.fuelecon+ ", fueletype=" + c1.fuelType);

    }

}

///////////////////////////////////////////////////////////////////////

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package constructortest;

class Data1 {

int value;

}


class Data2 {

int value;

Data2(int x) { // 매개변수가 있는 생성자.

value = x;

}

        Data2(){}

}


class ConstructorTest {

public static void main(String[] args) {

Data1 d1 = new Data1();

Data2 d2 = new Data2(); // compile error발생

}

}

//////////////////////////////////////////////////////////////////////

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package constructortest;

class Data1 {

int value;

}


class Data2 {

int value;

Data2(int x) { // 매개변수가 있는 생성자.

value = x;

}


}


class ConstructorTest {

public static void main(String[] args) {

Data1 d1 = new Data1();

Data2 d2 = new Data2(10); // compile error발생

}

}

////////////////////////////////////////////////////////////////////


'학교 실습 > HCI' 카테고리의 다른 글

130513  (0) 2013.05.13
20130508  (0) 2013.05.08
20130507  (0) 2013.05.07
HCI 20130429  (0) 2013.04.29
TVTEST  (0) 2013.04.17

HCI 20130429

학교 실습/HCI 2013. 4. 29. 14:27

/*

 * To change this template, choose Tools | Templates

 * and open the template in the editor.

 */

package overloadingtest;


/**

 *

 * @author User

 */

class OverloadingTest {


    public static void main(String args[]) {

        MyMath3 mm = new MyMath3();

        System.out.println("mm.add(3, 3) 결과:" + mm.add(3, 3));

        System.out.println("mm.add(3L, 3) 결과: " + mm.add(3L, 3));

        System.out.println("mm.add(3, 3L) 결과: " + mm.add(3, 3L));

        System.out.println("mm.add(3L, 3L) 결과: " + mm.add(3L, 3L));

        System.out.println("mm.minus(3, 3) 결과:" + mm.minus(3, 3));

        System.out.println("mm.minus(3L, 3L) 결과: " + mm.minus(3L, 3L));

        System.out.println("mm.minus(3L, 3) 결과: " + mm.minus(3L, 3));


        int[] a = {100, 200, 300};

        System.out.println("mm.add(a) 결과: " + mm.add(a));

    }

}


class MyMath3 {


    int minus(int a, int b) {

        System.out.print("int minus(int a, int b) - ");

        return a - b;

    }


    long minus(long a, long b) {

        System.out.print("int minus(long a, long b) - ");

        return a - b;

    }


    long minus(long a, int b) {

        System.out.print("int minus(long a, int b) - ");

        return a - b;

    }


    int add(int a, int b) {

        System.out.print("int add(int a, int b) - ");

        return a + b;

    }


    long add(int a, long b) {

        System.out.print("long add(int a, long b) - ");

        return a + b;

    }


    long add(long a, int b) {

        System.out.print("long add(long a, int b) - ");

        return a + b;

    }


    long add(long a, long b) {

        System.out.print("long add(long a, long b) - ");

        return a + b;

    }


    int add(int[] a) { // 배열의 모든 요소의 합을 결과로 돌려준다.

        System.out.print("int add(int[] a) - ");

        int result = 0;

        for (int i = 0; i < a.length; i++) {

            result += a[i];

        }

        return result;

    }

}

'학교 실습 > HCI' 카테고리의 다른 글

130513  (0) 2013.05.13
20130508  (0) 2013.05.08
20130507  (0) 2013.05.07
HCI 20130501  (0) 2013.05.01
TVTEST  (0) 2013.04.17