signal 함수에서..

Seven..의 이미지

(void)signal(SIGINT, func); 이렇게 하면

SIGINT(Ctrl_C)의 시그널이 발생할때
func함수가 실행되잖아요..

그런데 이때 func함수는

void func(int sig); 이렇게 되어서 SIGINT를 받는것 같더군요

func함수에 인자를 더 넘겨주고 싶은데

어떻게 하면 좋을까요?

func에서 int하나와 struct 형 하나가 필요한데..

그렇다고 전역으로 잡기는 코드가 찝찝해보이고;;

어떤 방법이 좋을까요? :oops:

sunyzero의 이미지

시그널 핸들러 함수는 미리 정의되어있는 것입니다.

임의로 바꿀수는 없으며 따라서 전역으로 잡고 쓰셔야 됩니다.

========================================
* The truth will set you free.

Seven..의 이미지

:(
결국 전역변수를 사용해야 한다는 거네요;;

에잇 -0- 영.. 보기가 ! -_- !

VENI VIDI VICI

bw001730의 이미지

#include <signal.h>

int sigaction(int sig, const struct sigaction *act, struct
sigaction *oact);

signal() 함수는 과거 호환성을 위하여 남아 있다고 합니다.

새로운 코드에서는 sigaction을 사용하시는게 좋다고 하네요

sigaction()은 signal() 함수에서 정의할수 없는
불명확한...동작들을.. 또는 시스템 마다 차이가 있는 동작들을..
프로그래머가 플래그 설정등을 통해서
원하는대로 할 수 있습니다. 포직스 표준이구용

암튼.. signal()인터페이스를 개선시켜서
프로그래머가 시스템에게 구체적으로 지시할수 있게 해준거죠
그래서.. sigaction을 사용하면
signal 핸들러를 한가지만 사용해야 하는 것은 아니구요
한개 더 사용할수 있습니다.

자세한건 매뉴얼을 보시구용

설정할수 있는 플래그에는 SIG_INFO가 있는데 이때
아래와 같은 핸들러를 사용하게 됩니다.

void (*sa_sigaction)(int, siginfo_t *, void *);
첫번째인자는 시그널번호..............
두번째 인자는 시그널발생원인같은 시그널 부가정보이구요
세번째 인자는 시그널 전달시 프로세스 컨텍스트 라고 하는데..
이것은 잘 모르겠네요..암튼 커널에 의해 채워지는 데이타들이죠

혹시...필요로 하는 부가정보가...
두번째 세번째 인자에 있을수도 있을것 같아서
함 적어봅니다.

늦은밤 야근하며.......

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.