z

BLOG ARTICLE 개발 | 82 ARTICLE FOUND

  1. 2019.10.15 특정CPU에서 프로세스 실행
  2. 2019.10.02 IT한글문서 목록
  3. 2019.10.01 크롬에서 exe 실행
  4. 2017.11.22 http session for httpclient
  5. 2017.07.06 Oracle SQL Model Clause

출처:https://sangheon.com/2010/04/20/1670

요즘 개인용 컴퓨터도 멀티코어를 장착하고 나올 정도로 멀티프로세서(Multiprocessor)가 흔해졌습니다. 덕분에 멀티프로세스(Multiprocess) 프로그래밍으로 개발한 데몬과 같은 것을 실행시켜 보면 여러 프로세서에 적당히 나뉘어 실행되는 것을 쉽게 확인 할 수 있습니다.

그런데 여기에 한가지 욕심을 더 내보자면 특정한 작업을 수행하는 프로세스를 특정한 프로세서에 할당하고 싶다는 생각이 드는 경우가 있습니다. 네트워크 데이터 및 DB 처리는 0번 CPU, 데이터 처리는 1번 CPU 식으로 말입니다.

기본적으로 OS에서 프로세스를 어떤 CPU에 할당하는지는 OS가 가진 자체적인 스케쥴링에 따르도록 되어 있습니다.

 

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

 

int main(int argc, char *argv[]) {
unsigned int i = 0;
pid_t pid;

 

if ( (pid = fork()) == 0 ) {
  for ( i = 0; i < UINT_MAX; i++) {
  }
}
else {
  int status;
  waitpid(pid, &status, 0);
}

return EXIT_SUCCESS;
}

 

위 소스는 1개의 자식 프로세스를 생성하고 더하기 연산을 반복적으로 수행하여 CPU를 100% 사용하게 만드는 예제입니다.

터미널을 하나 더 열어 top을 실행시킨 후 '1'번 키를 눌러 CPU 별로 사용량을 지켜볼 수 있게 준비를 합니다. 그리고, 소스를 컴파일 해서 여러번 실행시켜 보면 사용량이 100%에 달하는 CPU가 고정적이지 않고 변하는 것을 확인 할 수 있습니다. 물론 OS의 스케쥴링 정책에 영향을 받기 때문에 특정한 CPU에 고정적으로 할당되는 것처럼 보일 수도 있으나 많은 횟수를 실행시켜보면 변한다는 것을 확인 할 수 있습니다.

 

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <getopt.h>
#include <sched.h>

 

void print_help(char *cmd)

{
  printf("Usage: %s -n -c < 선호CPU>\n\n", cmd);
  printf(" CPU 개수 : CPU 코어 개수\n");
  printf(" 선호 CPU : CPU 코어 번호 (0 부터 시작)\n\n");
  printf(" 예 : 쿼드코어 CPU에서 3번째 코어를 사용하는 경우\n");
  printf(" $ %s -n 4 -c 2\n", cmd);
}

 

int main(int argc, char *argv[]) {
unsigned int i = 0;
pid_t pid;
int max_cpu = -1;
int cpu = -1;
int opt;

 

while ( (opt = getopt(argc, argv, "n:c:")) != -1 ) {
  switch ( opt ) {
    case 'c' :
      cpu = atoi(optarg);
      break;
    case 'n' :
      max_cpu = atoi(optarg);
      break;
    case '?' :
      default :
      print_help(argv[0]);
      exit(EXIT_FAILURE);
    break;
  }
}

 

if ( max_cpu < 1 || cpu < 0 || cpu >= max_cpu ) {
  print_help(argv[0]);
  exit(EXIT_FAILURE);
}

 

if ( (pid = fork()) == 0 ) {
  cpu_set_t mask;

  CPU_ZERO(&mask);
  CPU_SET(cpu, &mask);
  pid = getpid();
 

  if ( sched_setaffinity(pid, sizeof(mask), &mask) ) {
    fprintf(stderr, "%d 번 CPU를 선호하도록 설정하지 못했습니다.\n",
  cpu);
  exit(EXIT_FAILURE);
  }
  else {
    printf("%d 번 CPU를 선호하도록 설정했습니다.\n", cpu);
  }

 

  for ( i = 0; i < UINT_MAX; i++) {
  }
} else {
  int status;
  waitpid(pid, &status, 0);
}

return EXIT_SUCCESS;
}

 

위 소스 코드는 sched.h에서 제공하는 sched_setaffinity 함수를 사용하여 특정한 CPU에서 프로세스가 실행되도록 한 것입니다.

sched_setaffinity 함수는 3개의 매개변수를 받는데 첫번째는 프로세스 ID(pid)입니다. pid 대신 0을 넘기면 자동으로 현재 동작중인 프로세스로 설정됩니다. 두번째는 cpusetsize 입니다. 보통은 sizeof(cpu_set_t)로 설정하면 됩니다. 세번째는 mask 포인터입니다. mask 포인터는 아래의 매크로 함수들을 사용해서 편리하게 설정 할 수 있습니다.

 

void CPU_CLR(int cpu, cpu_set_t *set);
int CPU_ISSET(int cpu, cpu_set_t *set);
void CPU_SET(int cpu, cpu_set_t *set);
void CPU_ZERO(cpu_set_t *set);

 

cpu는 CPU의 번호로 0번부터 시작합니다. 쿼드코어 CPU 라면 0~3번 사이의 값이 됩니다. mask 값을 여러개의 CPU로 지정하는 것도 가능합니다.

sched.h가 정상적으로 동작하기 위해서는 꼭 헤더파일을 인클루드 하기 전에 #define _GNU_SOURCE를 선언 해주어야 합니다. 선언하지 않으면 CPU_XXXXX 매크로 함수를 찾을 수 없다며 컴파일 오류가 발생합니다.

멀티프로세스나 멀티쓰레드를 여러개의 CPU나 코어에 적절히 배치하여 효과적으로 사용하는 것은 매우 어려운 기술입니다. sched_setaffinity 함수를 통해 수동으로 배치했다고 해서 그것이 반드시 OS의 스케쥴링에 의한 배치보다 효율적이라는 보장은 없습니다.

다만 몇가지 특징적인 프로세스들을 적절히 배치하여 CPU 자원을 어느 정도 보장 해주는데 도움이 될 수 있다고 생각합니다.

AND

IT한글문서 목록

개발 2019. 10. 2. 15:21

IT도서 열람

https://thebook.io

 

더북(TheBook)

 

thebook.io

 

한국어 번역글 모음 페이지

https://nolboo.kim/trans/

 

한국어 번역글 모음 페이지

공유할만한 번역 글과 사이트를 크라우드 소싱 방식으로 이 위키에 모으려고 합니다. 널리 알리고 싶은 번역 글과 사이트를 마음대로 추가해주십시요. 위키 본문의 형식은 마크다운입니다. 마크다운은 배우기 쉬우니 처음 접하신 분은 존 그루버 마크다운 페이지 번역을 참조하실 수 있습니다. 이 위키에서 쓰인 문법은 ## 제목과 링크를 위한 []() 두가지 입니다. Edit 모드에서 간단한 도움말도 제공됩니다. 카테고리는 먼저 마크다운 형식의 헤더로 구분하고 숫자가

nolboo.kim

 

몽고DB개요

https://blog.voidmainvoid.net/239

 

NoSQL강의) mongoDB 개요 및 설명 한페이지에 끝내기(mapReduce, aggregate 예제 포함)

Humongous DB ▪ Document DB : BSON(Binary JSON) ▪ Auto Sharding ▪ Replica Set ▪ Index : Geospatial(위치정보 처리 index), Hashed, Unique, Spars, Compound - Embedded Document, Array 필드도 인덱싱..

blog.voidmainvoid.net

 

창의컴퓨팅 - 스크레치

http://digital.kyobobook.co.kr/digital/ebook/ebookDetail.ink?barcode=480150000247P

 

창의컴퓨팅(Creative Computing) 가이드북

본 도서는 미국 스크래치 팀에서 개발한 Creative Computing 가이드북의 번역서로써 경인교육대학교의 미래인재연구소에서 번역하였습니다. 최근 우리나라의 SW교육이 활성화 되고 있는데, 본 도서를 통해 초중등학생들에게 창의컴퓨팅을 어떻게 가르칠 수 있는지에 대한 방법을 고민하고 공유하고자 합니다. 본 도서에서는 학생들의 Computational Thinking을 어떻게 증진시킬 수 있는가에 대한 교육방법과 내용을 제시하고 있습니다. 본 도서의 보급

digital.kyobobook.co.kr

개발관련 - 노드, 펄 

https://github.com/EbookFoundation/free-programming-books/blob/master/free-programming-books-ko.md

 

EbookFoundation/free-programming-books

:books: Freely available programming books. Contribute to EbookFoundation/free-programming-books development by creating an account on GitHub.

github.com

슬라이드 쉐어

https://www.slideshare.net

 

SlideShare.net

Discover, Share, and Present presentations and infographics with the world’s largest professional content sharing community.

www.slideshare.net

 

AND

출처:http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=50&MAEULNo=20&no=975795&ref=975795&page=1

 

크롬에서 exe실행관련 질문 | 마을 :: 컨텐츠 상세보기

크롬에서 exe실행관련 질문 | 마을 :: 컨텐츠 상세보기

www.devpia.com

 

그 밖에 네트워크 실행 방법

- PNaCl / NaCl / asm.js / emscript-qt

- docker container

- 네트워크 드라이브

 

//

크롬에서 exe실행 - 구글 검색

 

크롬(chrome)에서 로컬 exe파일 실행하는 방법 (ActiveX 대체) :: 나는 ...

https://developerking.tistory.com/71

크롬(chrome)에서 로컬 exe파일 실행하는 방법 (ActiveX 대체) :: 나는 ...

https://developerking.tistory.com/71

 

[JS] 웹페이지에서 EXE 실행시키기(에대한 잡담) - 아는게1도없다

https://daydreamer-92.tistory.com/15

 

Chrome OS 에서의 exe 파일 실행 - Google Product Forums

https://productforums.google.com/d/msg/chrome-ko/.../h6FXMDRfO9IJ

 

OKKY - 웹에서 로컬프로그램 실행하는 방법이 있을까요???

https://okky.kr/article/333701?note=1080738

 

크롬 브라우저에서 로컬 file경로 Sencah Application을 실행하기

blog.saltfactory.net/open-local-file-from-chrome-to-sencha/

 

응용프로그램 실행하기 - MDN - Mozilla

https://developer.mozilla.org/ko/docs/Code_snippets/Running_applications

 

ActiveX 방식과 그 대안 방식인 EXE 방식의 문제점에 대한 고찰 :: 학 ...
https://poem23.com/3185

 

html5 기반 의 activex 대체 기법non-activex 방식activex 제거 이행 계획

 

액티브 엑스 만든 새끼html5 exe 실행activex 취약점

[Chrome] 크롬에서 로컬파일 접근하기 : 네이버 블로그

m.blog.naver.com/romeoh/140170583860

Kern :: JAVA 외부 프로그램 실행하기

https://lazydev.tistory.com/29

KR20160129715A - 웹브라우저와 응용 프로그램 간의 연동 시스템 및 ...

https://patents.google.com/patent/KR20160129715A/ko

크롬 프로세스 exe 파일 실행수가 엄청나군요 : 클리앙

https://www.clien.net/service/board/park/7493821

Chrome.exe은(는) 무엇이고 어떻게 해결하죠? 바이러스인가요?

https://www.solvusoft.com/ko/files/오류-바이러스-제거/exe/...chrome/chrome-exe/

ChromeStandaloneSetup.exe은(는) 무엇이고 어떻게 해결하죠 ...

https://www.solvusoft.com/ko/files/오류.../exe/.../chrome/chromestandalonesetup-exe/

html5 hta - Firefox, Chrome의 동등한 기능 -이 오래된 기술입니까 ...

https://code.i-harness.com/ko-kr/q/a20c56

javascript 크롬 자바스크립트 - Chrome에서 동일한 출처 정책을 사용 ...

https://code.i-harness.com/ko-kr/q/2f5863

 

Untitled - 한국인터넷진흥원

https://www.kisa.or.kr/jsp/common/downloadAction.jsp?bno=4&dno=1597&fseq...

 

인터넷 링크를 크롬으로 열고 싶은데 익스플로러로 열립니다 ...

 

https://answers.microsoft.com/ko-kr/.../48f5732e-90f9-4a4c-9f50-5347b8035602

NPAPI - 나무위키

https://namu.wiki/w/NPAPI

selenium 크롬 자동화 할 때 현재 실행중인 크롬에서 실행하기

https://yonoo88.tistory.com/1237

Chrome을 가상 애플리케이션으로 실행 - Google Chrome Enterprise ...

https://support.google.com/chrome/a/answer/7380899?hl=ko

 

 

AND

회사에서 login을 주기적으로 확인하여

 

 

HTTPClient 3.0으로 로그인을 테스트를 할 수 있다.

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

문제는 https 다.

난 이렇게 해결했다.

 

HTTPClient 3.0 버젼

 

        HttpClient client = new HttpClient();

         client.getState().setCredentials(
            new AuthScope("ids.google.com", 443 ),
            new UsernamePasswordCredentials("", "" )
        );

         client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");
        client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

            PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

 

 

 

 

 

HTTPClient 2.0 버젼

 

 

         HttpClient client = new HttpClient();

         client.getState().setCredentials(
                "realm", "ids.google.com",
                new UsernamePasswordCredentials("", "" )
            );

       client.getHostConfiguration().setHost("i4h080.google.com", LOGON_PORT, "https");

 

       PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }

    }

 

 

 

HTTPClient 2.0으로도 로그인을 테스트를 할 수 있다.

 

 

 

 
public class Login {

    private static Log log = LogFactory.getLog(Login.class);

 

    private static String LOGON_SITE = "i4h082.google.com";

 

    private static int LOGON_PORT = 80;

 

    static HttpClient client = new HttpClient();

    public static void loginID() {

        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
        PostMethod authpost = new PostMethod("/login.ggl");
        NameValuePair nextURL = new NameValuePair("nxtURL","http://www.google.com/login.ggl");
        NameValuePair secukey = new NameValuePair("secukey", "");
        NameValuePair turtle = new NameValuePair("sqer", "knight76");
        NameValuePair earthworm = new NameValuePair("max", "xa");

        authpost.setRequestBody(new NameValuePair[] { nextURL, secukey, sqer,max });

        String response = null;
        try {
            client.executeMethod(authpost);
            response = authpost.getResponseBodyAsString();
        } catch (IOException ioe) {
            log.error(ioe, ioe);
        } finally {
            authpost.releaseConnection();
        }

        authpost.releaseConnection();
        int statuscode = authpost.getStatusCode();

        if (statuscode == HttpStatus.SC_OK && (response.indexOf("성공") > 0)) {
            System.out.println("login is successed");
        } else {
            System.out.println("login is failed");
        }



출처: http://knight76.tistory.com/298 [김용환 블로그(2004-2017)]

 

 

https://stackoverflow.com/questions/6272575/how-to-handle-the-session-in-httpclient-4-1

 

I am using the HttpClient 4.1.1 to test my server's REST API.

I can manage to login seem to work fine but when I try to do anything else I am failing.

Most likely I have a problem setting the cookie in the next request.

Here is my code currently:

HttpGet httpGet = new HttpGet(<my server login URL>);
httpResponse = httpClient.execute(httpGet)
sessionID = httpResponse.getFirstHeader("Set-Cookie").getValue();
httpGet.addHeader("Cookie", sessionID);
httpClient.execute(httpGet);

Is there a better way to manage the session/cookies setting in the HttpClient package?

 

 

The correct way is to prepare a CookieStore which you need to set in the HttpContext which you in turn pass on every HttpClient#execute() call.

HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
// ...

HttpResponse response1 = httpClient.execute(method1, httpContext);
// ...

HttpResponse response2 = httpClient.execute(method2, httpContext);
// ...

 

AND


Oracle 10g SQL MODEL Clase.pdf

 

AND