중복 실행 막기

purewell의 이미지

ㅡ_-)v Windows의 팁으로는 Mutex 객체(아마 MFC팁에서인 듯...)를

이용해서 동일 프로세스가 돌아가는 것을 막았는데

ㅡ_-)a 리눅스에서는 어떻게 해야하나요!?

나름대로 돌을 굴려본 결과로

pid 파일을 만들고 그 파일을 쓰기락을 걸면

동일 프로세스가 그 파일을 쓰려고 할 때, 쓰기 실패가 일어나면

이미 동일 프로세스가 돌아가는 것으로 인식하는...

어떻게 해야하나요~?

Always wish be pure well...

berise의 이미지

뮤텍스는 리눅스에도 제공합니다.

윈도우즈에서 했던 방식으로 리눅스에서 코딩하세요.

이만.

skjk의 이미지

Windows에서 제공하는 mutex는 프로세스간에 동기화처리를 할 수 있지만 Linux에서 pthread에서 제공하는 mutex는 한 프로세스안의 쓰레드끼리들의 동기화만 처리할 수 있습니다. (즉 Windows의 Critical Section과 같습니다)

Linux에서는 IPC인 Semaphore나 Shared Memory를 써야지 프로세스간 동기화 처리를 할 수 있습니다.

sangheon의 이미지

저는 Shell Script 로 처리 합니다. /etc/init.d 안의 스크립트들을 보시면
좀 더 똑똑하게 되어있죠. 8)

단, cron 으로 실행하신다면 current directory 나 environment variables
에 신경을 쓰셔야 할 겁니다.

#!/bin/sh

[ -f foobar.lock ] && exit 1

[ -f foobar ] || exit 2

# lock file 생성
touch foobar.lock

./foobar

# lock file 삭제
rm -f foobar.lock

exit 0

--

Minimalist Programmer

unixguy의 이미지

skjk wrote:
Windows에서 제공하는 mutex는 프로세스간에 동기화처리를 할 수 있지만 Linux에서 pthread에서 제공하는 mutex는 한 프로세스안의 쓰레드끼리들의 동기화만 처리할 수 있습니다. (즉 Windows의 Critical Section과 같습니다)

Linux에서는 IPC인 Semaphore나 Shared Memory를 써야지 프로세스간 동기화 처리를 할 수 있습니다.

:lol:

제가 알고 있기로는 mutex 가 공유메모리내에 위치하고 있으면 프로세스간에도 동기화 처리할 수 있는 걸로 알고 있습니다. 확인해 보시기를 ...

skjk의 이미지

POSIX Thread를 보면 Mutex만들 때 특정 옵션을 줘서 Shared Memory에 올려놓으면 다른 Process에 있는 Thread간도 동기화 처리를 할 수 있다고 합니다.

하지만 이경우에 다른 Process가 Mutex로 lock을 얻은 상태에서 만약 그 Process가 자체적으로 종료처리할 기회를 얻지 못하고 죽어버리게 되는 경우 Mutex의 lock을 풀지 못하고 죽어버려서 Deadlock이 걸릴 수 있는 거로 알고 있습니다.
그래서 Process간 mutex는 쓰지 않는 것이 좋은 걸로 알고 있습니다.

Programming with Threads (Prentice Hall)에서 본 내용입니다. 그래서 저 문제를 해결하는 다른 방법이 있는지는 모르겠네요.. 혹시 있다면 알려주시면 좋겠습니다~ ^^

체스맨의 이미지

unixguy wrote:
skjk wrote:
Windows에서 제공하는 mutex는 프로세스간에 동기화처리를 할 수 있지만 Linux에서 pthread에서 제공하는 mutex는 한 프로세스안의 쓰레드끼리들의 동기화만 처리할 수 있습니다. (즉 Windows의 Critical Section과 같습니다)

Linux에서는 IPC인 Semaphore나 Shared Memory를 써야지 프로세스간 동기화 처리를 할 수 있습니다.

:lol:

제가 알고 있기로는 mutex 가 공유메모리내에 위치하고 있으면 프로세스간에도 동기화 처리할 수 있는 걸로 알고 있습니다. 확인해 보시기를 ...

pthread 라이브러리 자체 spec 은 뮤텍이 프로세스간 동기화 처리도
할 수 있으나, 리눅스는 그렇지 못합니다. skjk 님 말씀대로 입니다.

제가 KLTP 에 올렸던 글을 참고 하세요.
http://kltp.kldp.org/stories.php?story=01/07/05/2982955

Orion Project : http://orionids.org

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.