윤블린
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    함수들 잘 정리 되어있는 곳 : 예제까지 완전 잘 정리되어있어요! #### malloc #### free #### write #### open #### read #### close #### fork - pid_t fork(void) - 현재 실행중인 프로세스와 동일한 기능을 하는 새로운 프로세스 생성 - 부모와 자식의 PPID는 같음 - a에서 b를 실행하려면 fork + execve함수를 사용하여 실행 - fork를 통해 새로운 프로세스 생성, execve함수를 통해 새로운 명령으로 덮어짐 - b가 종료되고 난 결과는 a에서 처리 가능 - return value - 양수 - 해당 프로세스는 부모 프로세스이며, 리턴된 값은 자식의 PID - child의 종료를 대기하거나 SIGCHILD에 대한 signal 처리를 위해 필요함 - 별도로 자식 pid를 얻을 방법은 없음 - 0 - 해당 프로세스는 자식 프로세스 - -1 - 오류가 발생하여 자식이 생성되지 않음 - 상세 내용은 errno에 세팅됨 #### wait - pid_t wait(int *statloc); - 임의의 자식 프로세스가 종료될 때까지 기다림 - statloc에 사용 가능한 매크로들 - WIFEXITED(status) 자식 프로세스가 정상적으로 종료된 경우 true - WIFEXITEDSTATUS(status) exit()의 인자에서 하위 8비트 값을 리턴 - WIFSIGNALED(status) 자식 프로세스가 시그널을 받아 비정상적으로 종료된 경우 true - WIFTERMSIG(status) 시그널 번호를 리턴 - WIFCOREDUMP(status) 코어 파일이 생성된 경우 true - WIFSTOPPED(status) 현재 중지 상태이면 true - WSTOPSIG(status) 실행을 중단시킨 시그널 번호를 리턴 - WIFCONTINUED(status) 작업 제어 중지 이후 실행이 재개되었으면 true - return value - -1 - 실패시 (자식 프로세스가 없거나 or 시스템 콜이 인터럽트 되었을 때) - 그 외 - pid 번호 #### waitpid - pid_t waitpid(pid_t pid, int *statloc, int options); - 임의의 pid를 기다리는 wait과 다르게 특정 pid를 가진 자식 프로세스가 종료될 때까지 기다림 - pid: 기다릴 자식 프로세스의 pid 번호 - statloc: wait의 statloc와 같음. - options: 어떤 상태의 자식까지 리턴할지를 옵션으로 설정 - WCONTINUED 중지되었다가 실행을 재개한 이후 상태가 아직 보고되지 않은 자식도 리턴함 - WNOHANG 종료 상태를 즉시 회수 할 수 없는 상황이라고 하여도 waitpid() 호출이 차단되지 않고 0을 리턴함 - WUNTRACED 중지되었으나 그 상태가 아직 보고되지 않은 자식도 리턴함 - return value - -1 - 실패시 (자식 프로세스가 없거나 or 시스템 콜이 인터럽트 되었을 때) - 그 외 - pid 번호 #### wait3 - pid_t wait3(int *statloc, int options, struct rusage *rusage) - wait에서 option과 rusage (종료된 자식 프로세스의 리소스 사용량을 리턴)이 추가된 것 - statloc: wait의 statloc와 같음. - options: waitpid의 option과 같음. - rusage: 자식 프로세스의 리소스 사용랴에 대한 정보를 리턴 - return value - -1 - 실패시 (자식 프로세스가 없거나 or 시스템 콜이 인터럽트 되었을 때) - 그 외 - pid 번호 #### wait4 - pid_t wait4(pid_t pid, int *statloc, int options, struct rusage *rusage); - wait3에서 pid 번호를 추가한 함수 - pid: 기다릴 자식 프로세스의 pid 번호 - statloc: wait의 statloc와 같음. - options: waitpid의 option과 같음. - rusage: 자식 프로세스의 리소스 사용랴에 대한 정보를 리턴 - return value - -1 - 실패시 (자식 프로세스가 없거나 or 시스템 콜이 인터럽트 되었을 때) - 그 외 - pid 번호 #### signal - void (*signal(int signum, void (*handler)(int)))(int) - 프로그램이 특정 시그널을 받았을 때의 행위를 설정 - signum: 시그널 번호, signal.h에 정의됨 - c 표준 시그널 - SIGABRT - aboart, 비정상적 종료 - SIGFPE - 부동소수점 - SIGILL - illegal, 유효하지 않은 명령어 - SIGINT - interrupt, 프로그램에서 보내진 상호적인 요청 - SIGSEGV - segmentation fault, 유효하지 않은 메모리 접근 - SIGTERM - terminate, 프로그램에 보내진 종료 요청 - void (*handler)(int): 시그널 발생 시 처리할 핸들러 - return value - void *()(int): 이전에 설정된 시그널 핸들러 - 기본적으로 SIG_DFL이 설정되어 있음 #### kill - int kill(pid_t pid, int sig) - 쉘 명령인 kill과 다르게 프로세스에 시그널을 전송함 - SIGKILL을 보내면 쉘의 kill과 같은 역할을 함 - pid: 시그널을 받을 프로세스의 id - 양수 - 지정한 프로세스에만 전송 - 0 - 함수를 호출하는 프로세스와 같은 그룹에 있는 모든 프로세스에 시그널을 전송 - -1 - 함수를 호출하는 프로세스가 전송할 수 있는 권한을 가진 모든 프로세스에 시그널을 전송 - -1 아닌 음수 - 첫번째 인수 pid의 절대값 프로세스 그룹에 속하는 모든 프로세스에 시그널을 전송 - sig: pid로 지정된 프로세스에 보내려는 시그널 - return value - 0 - 성공 - -1 - 실패 #### exit - void exit(int status) - status: parent process가 반환하는 값 - 프로그램을 정상종료 시키며, 종료 값으로 status를 부모 프로세스에 status & 0377로 넘겨줌 - 부모 프로세스는 wait를 이용해서 자식 프로세스의 종료 값을 ㅇ읽어 올 수 있음 #### getcwd - char *getcwd(char *buf, size_t size) - 현재 경로가 buf에 반환됨 - 실패하면 null이 반환됨, 성공하면 그냥 경로 나옴 - size는 경로의 길이 값 - 0이면 실패, 경로+1보다 작은 값이면 실패 - ex) #include <unistd.h> #include <stdio.h> int main(void) { char buf[255]; getcwd(buf, 255); printf("%s\n", buf); } #### chdir - int chdir(const char *path) - 작업 디렉토리 변경 - path: 변경할 절대/상대 경로 - return value - 0: 성공 - -1: 실패, errno에 상세 내용 #### stat 구조체 struct stat { dev_t st_dev; // 디바이스 번호 ino_t st_ino; // inode 번호 mode_t st_mode; // 모드 (접근권한) nlink_t st_nlink; // 하드링크 수 uid_t st_uid; // 소유자의 사용자 아이디 gid_t st_gid; // 소유자의 그룹 아이디 dev_t st_rdev; // 디바이스 아이디 (특수 파일인 경우) off_t st_size; // 파일 크기(바이트) blksize_t st_blksize; // 블록 크기 blkcnt_t st_blocks; // 512바이트 블록 갯수 time_t st_atime; // 최종 접근 시간 (access time) time_t st_mtime; // 최종 수정 시간 (modification time) time_t st_ctime; // 최종 상태 변경 시간 (change time) }; #### stat - int stat(const char *filepath, struct stat *statbuf) - filepath에 존재하는 파일의 상태를 statbuf에 저장함. - filepath: 파일의 경로 - statbuf: 파일의 상태를 서술하는 구조체 - return value: - 0: 성공 - -1: 실패, errno에 상세 내용 #### lstat - int lstat(const char *filepath, struct stat *statbuf); - stat는 filepath의 파일이 심볼릭 링크 파일이라면 링크된 파일의 정보를 출력하지만, lstat은 심볼릭 링크 파일 자체의 파일 정보를 출력함. - filepath에 존재하는 파일의 상태를 statbuf에 저장함. - filepath: 파일의 경로 - statbuf: 파일의 상태를 서술하는 구조체 - return value: - 0: 성공 - -1: 실패, errno에 상세 내용 #### fstat - int fstat(int fd, struct stat *statbuf) - stat은 filepath로 파일을 명시하지만, fstat은 fd로 파일 명시 - filepath에 존재하는 파일의 상태를 statbuf에 저장함. - filepath: 파일의 경로 - statbuf: 파일의 상태를 서술하는 구조체 - return value: - 0: 성공 - -1: 실패, errno에 상세 내용 #### execve - int execve(const char *filename, char *const argv[], char *const envp[]) - 실행가능한 파일인 filename의 실행코드를 현재 프로세스에 적재하여 기존의 실행코드와 교체하여 새로운 기능으로 실행함 - filename - 교체할 실행 파일/명령어 - filename은 실행가능한 binary거나 shell - 절대경로나 상대경로로 표시해야 함 - argv - main함수의 argv와 비슷함 - 마지막 값은 NULL을 넣어야 함 - envp - key=value형식의 환경변수 문자열 배열리스트 - 마지막은 NULL - 만약 기존에 설정된 환경변수를 사용하려면 environ 전역변수를 그냥 사용 - return value - 없음 - 정상적으로 실행되면 지정된 프로그램의 로직으로 실행되므로 return 값을 받을 수 없음 - -1 - 실패함. 상세내용은 errno #### dup - int dup(int fd) - fd가 가리키는 파일을 가리키는 새로운 파일 디스크립터 생성 - fd와는 독립적이지만 같은 파일에 접근 할 수 있음 - return value - 새로운 파일 디스크립터 - 실패 시 -1 #### dup2 - int dup2(int old_fd1, int new_fd2) - fd2가 fd1이 가리키는 파일을 가리키게 됨 - return value - 새로운 파일 디스크립터 - 실패 시 -1 #### pipe - int pipe(int fd[2]) - 서로 독립된 프로세스들이 데이터를 주고 받기 위해 제공됨 - 하나의 파이프 및 파이프에 대한 두 개의 파일 디스크립터가 생성 - 하나의 파이프를 프로세스들이 공유 - fd - fd[0] - 함수 호출 후 fd[0]에 데이터를 입력 받을 수 있는 파일 디스크립터가 담김(파이프 출구) - 함수 호출 후 데이터를 출력할 수 있는 파일 디스크립터가 담김(파이프 입구) - return value - -1 - pipe 생성 실패 - 0 - 성공 - 부모 자식간에 양방향 통신을 원하면 pipe() 두개가 필요함 open/read/closedir은 파일처럼 디렉토리를 열고, 디렉토리 안에 있는 파일/디렉토리 목록을 조회하고, 파일처럼 디렉토리를 닫는 함수들 #### opendir - DIR *opendir(const char *filepath) - filepath에 존재하는 폴더를 열어서 DIR 구조체에 넣어 리턴 - filepath: 폴더의 경로 - return value - 널이 아닌 포인터 - 성공 - 널 포인터 - 실패 #### dirent 구조체 struct dirent { char d_name[256]; // 파일명 ino_t d_ino; // inode off_t d_off; // 현재 디렉토리 DIR 스트림내에서의 위치(offset) unsigned short d_reclen; // 레코드 길이 unsigned char d_type; // 파일의 타입 }; #### readdir - struct dirent *readdir(DIR *dp) - 디렉토리 포인터 dp에 포함된 디렉토리와 파일을 리턴 (단, 하나씩 리턴하므로 while문으로 써야함) - dp: 조회할 디렉토리의 포인터 - return value - 널이 아닌 포인터 - 성공 - 널 포인터 - 실패 #### closedir - int closedir(DIR *dp) - 디렉토리를 닫는다 - dp: 조회할 디렉토리의 포인터 - return value - 0 - 성공 - -1 - 실패함. 상세 내용은 errno #### strerror #### errno

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully