From: Jorge Opaso Pazos <jopaso@trofeospazos.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: Question!
Date: Thu, 04 Sep 2003 13:20:13 -0400 [thread overview]
Message-ID: <3F57744D.4000702@trofeospazos.com> (raw)
In-Reply-To: <20030904140125.GA24691@lsd.di.uminho.pt>
Luciano Miguel Ferreira Rocha wrote:
> On Wed, Sep 03, 2003 at 03:19:44PM -0300, Mariano Moreyra wrote:
>
>>Hi!!
>>First...I'd like to know if there is any kind of digest on this list to see
>>old submited messages.
>>
>>Now...I have a little problem.
>>I have a process that is listening for incoming connections on a socket.
>>That process waits for a command and then
>>forks a child to run a bash script.
>>The problems is:
>> - When the bash script runs the safe_mysql script to run MySql engine, it's
>>like the child process never ends.
>> And because of that, the parent can't close the connection with the
>>client socket.
>> - But if the bash script doesn't run the safe_mysql script...the child
>>process dies successfully and everything end
>> Ok
>>
>
> Hola,
>
> Your problem should be the socket inherited by the child that will run
> the script. I suppose the child doesn't need it, does it?
>
> So, close it and redirect /dev/null to stdin, stdout and stderr:
> if ((fork() == 0) { /* child */
> int fd;
> close(sock);
> fd = open("/dev/null", O_RDONLY);
> if (fd != 0) {
> dup2(fd, 0);
> close(fd);
> }
> fd = open("/dev/null", O_WRONLY);
> if (fd != 1) {
> dup2(fd, 1);
> close(fd);
> }
> fd = open("/dev/null", O_WRONLY);
> if (fd != 2) {
> dup2(fd, 2);
> close(fd);
> }
> execl("/usr/bin/safe_mysqld", "safe_mysqld", 0);
> _exit(1);
> }
>
> Regards,
> Luciano Rocha
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
Hi, Luciano:
popen redirect the stdout of the child to the stream created if the call
is in the form:
FILE f = popen("cmd", "r");
Bye.
prev parent reply other threads:[~2003-09-04 17:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-03 18:19 Question! Mariano Moreyra
2003-09-03 21:09 ` Question! Jorge Opaso Pazos
2003-09-04 13:51 ` Question! Mariano Moreyra
2003-09-04 14:05 ` Question! Luciano Miguel Ferreira Rocha
2003-09-04 14:28 ` Question! Mariano Moreyra
2003-09-04 16:04 ` Question! Jorge Opaso Pazos
2003-09-04 17:53 ` Question! Luciano Miguel Ferreira Rocha
2003-09-04 18:41 ` Question! Mariano Moreyra
2003-09-04 19:32 ` Question! Luciano Miguel Ferreira Rocha
2003-09-05 4:16 ` Question! Jorge Opaso Pazos
2003-09-05 14:58 ` Question! Mariano Moreyra
2003-09-04 14:01 ` Question! Luciano Miguel Ferreira Rocha
2003-09-04 17:20 ` Jorge Opaso Pazos [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3F57744D.4000702@trofeospazos.com \
--to=jopaso@trofeospazos.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).