exec() 함수로 프로세스를 실행시키면서 그 프로그램을 백그라운드로 돌릴 수는 없나요?

emeraldrhapsody의 이미지

int proc_On()
{
char *p_Path = "/root/cfgcheck/cfg-check";

execl(p_Path, "&", NULL);

return 0;
}

exec() 계열 함수 이것저것 살펴보고 백그라운드로 돌리려고 "&"를 줘봤는데요..

그냥 foreground로 실행이 되더라구요...

도와주시면 감사하겠습니다..

이 방법 말고도 다른 좋은 방법있다면 알려주세요~

익명 사용자의 이미지

execl()은 현재 돌아가는 (자신의) 프로세스를 execl인자로 수행되는 프로세스로 내용을 바꿔치기하는겁니다.

원하는 작업을 하려면
자식 프로세스를 생성해서 그 프로세스에서 execl()을 해야겠죠. ^^

emeraldrhapsody의 이미지

저 함수가 fork() 한 뒤에 호출되거든요..

int pid = fork();

if ( pid < 0 )
{
fprintf(stderr, "Fork() Failed.\r\n");
}
else if (pid == 0)
{
execl("bin/ls", "ls", "-l", NULL);
}
else
{
wait(NULL);
int ret = proc_On();

if ( ret != 0 ) exit(-1);

exit(0);
}

현재 /root/cfgcheck/cfg-check & 또는 ./cfg-check & 이렇게 실행하는 것을

Manager start 했을때 cfg-check가 백그라운드로 도는것을 원합니당..

Manager start & 하면 cfg-check가 백그라운드로 돌긴 하는데 백그라운드 자체 인자를 안주길 원하는 거에요...

ymir의 이미지

background process 는 fork 한 후에 tcsetpgrp() 로 controlling terminal 을 바꿔주면 됩니다.

근데 왠지 느낌이 daemon process 를 만들고 싶은건데, background process 라고 잘못 쓰신것 같은 느낌이 드는군요.

cfg-check 가 무한 loop 도는 프로그램이라서 daemon 으로 띄우고 싶으신거면.. cfg-check 에 daemon() 함수를 추가해 주면 되고..
수정이 어렵다 싶으면 parent 에서 fork 한 후에, child 에서 한 번 더 fork 해서 child 는 그냥 죽어버리고, grand-child 에서 exec 을 해보시죠..?
cfg-check 를 실행하는 쉘 스크립트를 하나 만들고, 쉘 스크립트 내에서 cfg-check & 로 실행하는 것도 괜찮을 것 같군요.
parent 에서는 쉘 스크립트만 실행해 주면 되겠죠.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

댓글 달기

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