fork fails

Hi all,

I have the following problem:
I’m doing fork/exec on QNX momentics (6.2.1a) in a function that is called from different places in my code. The first time when I call it fork acts normally and the exec passes, but the second time when I call it I get the following error:

[SMA] ps_list: start
[SMA] ps_list: Function not implemented
[SMA] ps_list: failed to exec pidin!

Can anyone tell me what might be the problem?
The code fragment that produces the error is:

sma_debug(“ps_list: start”);
opdatas[0] = (opdata_t*) sma_malloc(sizeof(opdata_t));
opdatas[0]->size = 0;
opdatas[0]->data = NULL;

pipe(fds);
cpid = fork();
if(cpid == -1){
sma_warning(“ps_list: %s”, strerror(errno));
}
if(cpid == (pid_t) 0){
sma_debug(“ps_list: child!”);
close (fds[0]);
dup2 (fds[1], STDOUT_FILENO);
execlp (“pidin”, “pidin”, “-f”, “acdn”, NULL);
abort();
} else {

waitpid (cpid, &i, 0);
if (!WIFEXITED(i)){
sma_warning(“ps_list: failed to exec pidin!”);
return -1;
}
close (fds[1]);
stream = fdopen (fds[0], “r”);
/* get the lables line! */
fgets(line, PS_LINESIZE, stream);

also,

Can anyone point me to a good guide on using procfs on qnx6.2?
The docs on support.qnx.com are quite poor (when it comes to /proc mangling), and the ones that I found on the net were for pretty old APIs (pre 6.2)…

Thanks in advance!

Best Regards,

Alexander Popov ProSyst Bulgaria Inc.
Tech Leader 48 Vladajska Str.
RTOS and JVM Dept. Sofia 1606, Bulgaria
Phone: +359 2 952 3581/204 http://www.prosyst.com
Mobile: +359 887 663 193 OSGi Technology Leaders

Alexander Popov <s_popov@prosyst.bg> wrote:

Hi all,

I have the following problem:
I’m doing fork/exec on QNX momentics (6.2.1a) in a function that
is called from different places in my code. The first time when I
call it fork acts normally and the exec passes, but the second time
when I call it I get the following error:

[SMA] ps_list: start
[SMA] ps_list: Function not implemented
[SMA] ps_list: failed to exec pidin!

Have you created any threads in your process? QNX does not allow
a fork() after threads have been created.

If so, you might look at calling spawn(), and using the
fd_map[] parameter to do the fd redirection. (Note: this will
also be far more efficient than fork() & exec().)

Also, there is a bug in your code. You fall through into the
waitpid() branch of the if, even when you failed the fork().


Can anyone tell me what might be the problem?
The code fragment that produces the error is:
cut
sma_debug(“ps_list: start”);
opdatas[0] = (opdata_t*) sma_malloc(sizeof(opdata_t));
opdatas[0]->size = 0;
opdatas[0]->data = NULL;

pipe(fds);
cpid = fork();
if(cpid == -1){
sma_warning(“ps_list: %s”, strerror(errno));
}
if(cpid == (pid_t) 0){

That line needs to be:

else if(cpid == (pid_t) 0){

sma_debug(“ps_list: child!”);
close (fds[0]);
dup2 (fds[1], STDOUT_FILENO);
execlp (“pidin”, “pidin”, “-f”, “acdn”, NULL);
abort();
} else {

waitpid (cpid, &i, 0);
if (!WIFEXITED(i)){
sma_warning(“ps_list: failed to exec pidin!”);
return -1;
}
close (fds[1]);
stream = fdopen (fds[0], “r”);
/* get the lables line! */
fgets(line, PS_LINESIZE, stream);
cut

also,

Can anyone point me to a good guide on using procfs on qnx6.2?
The docs on support.qnx.com are quite poor (when it comes to /proc
mangling), and the ones that I found on the net were for pretty
old APIs (pre 6.2)…

I don’t know of anything good on procfs mangling. :frowning:

-David

QNX Training Services
http://www.qnx.com/services/training/
Please followup in this newsgroup if you have further questions.

On 4 Aug 2004 22:11:46 GMT David Gibbs <dagibbs@qnx.com> wrote:

Thanks David,

Have you created any threads in your process? QNX does not allow
a fork() after threads have been created.

If so, you might look at calling spawn(), and using the
fd_map[] parameter to do the fd redirection. (Note: this will
also be far more efficient than fork() & exec().)

That’s exactly the case - this code snippet is executed in a thread unlike the first call of this function. I’ll check out spawn().

Also, there is a bug in your code. You fall through into the
waitpid() branch of the if, even when you failed the fork().

Yep, I noticed that last night - the code is quite fresh and there still are similar stupidities in it. Thanks for pointing it.

I don’t know of anything good on procfs mangling. > :frowning:

Pity. I found a good article in qnx.org.ru but many of the examples in it were not doing what I expected them to do. Probably the article is too old…
I’ll try and experiment a bit more with the stuff defined in sys/procfs.h and sys/syspage.h and post the problems here.

-David

QNX Training Services
http://www.qnx.com/services/training/
Please followup in this newsgroup if you have further questions.

Regards,
Sasho

Alexander Popov ProSyst Bulgaria Inc.
Tech Leader 48 Vladajska Str.
RTOS and JVM Dept. Sofia 1606, Bulgaria
Phone: +359 2 952 3581/204 http://www.prosyst.com
Mobile: +359 887 663 193 OSGi Technology Leaders

Alexander Popov <s_popov@prosyst.bg> wrote:
[snip]

also,

Can anyone point me to a good guide on using procfs on qnx6.2?
The docs on support.qnx.com are quite poor (when it comes to /proc mangling), and the ones that I found on the net were for pretty old APIs (pre 6.2)…

What do you want to do ? The “QNX Cookbook” has an appendix on the /proc filesystem,
and there are several examples that dig into /proc and get stuff.

See http://www.parse.com/products/books/book_v2/index.html

Cheers,
-RK

[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

John Nagle <nagle@downside.com> wrote:

Robert Krten wrote:
What do you want to do ? The “QNX Cookbook” has an appendix on the /proc filesystem,
and there are several examples that dig into /proc and get stuff.

Bob, you’ve got to implement online ordering. The books
are great, but getting them is just too hard. I know you
complain about what a big cut amazon.com wants, but that’s
the way retail works.

Just get them from QNX – I’m sure they must have an online ordering system… :slight_smile: :slight_smile:

It’s an interesting conundrum – as I’ve emailed with you before, Amazon
would need to sell 4X the volume to make the same amount of money.

Is it likely they will sell 4X the volume? No. They might sell 1.5X the
volume, perhaps as much as 2X the volume. So, the correct business decision
answer is, “Yes, that may be the way that retail works, but why should I
reduce the amount of money I make?” I have yet to hear a successful defence
for making less money. :slight_smile:

Where things get really interesting is this: go to Amazon.com and look for
the “Getting Started with QNX Neutrino 2” book. Notice that Amazon doesn’t
sell them. Notice that someone else does, for an amazingly low price of
US$188.41. Yes, that’s right. WELL OVER THREE TIMES RETAIL.

And you know what? People are buying them. I tracked down the person who
orders them at full retail from me, and resells them on Amazon. I congratulated
her on being a far more successful capitalist than I am.

So. Here’s a business opportunity for you, John :slight_smile: Fax or call me with your
credit card number, and I’ll ship books to you at full retail. You can make
$BIGBUX$ on Amazon with them. To reorder, just send me an email. It’ll be
just like online ordering. :slight_smile: (Why don’t I do this myself? You need a US
mailing address to take part in the Amazon “slightly used books” reselling
scam.)

John Nagle
Animats

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

Robert Krten wrote:

What do you want to do ? The “QNX Cookbook” has an appendix on the /proc filesystem,
and there are several examples that dig into /proc and get stuff.

Bob, you’ve got to implement online ordering. The books
are great, but getting them is just too hard. I know you
complain about what a big cut amazon.com wants, but that’s
the way retail works.

John Nagle
Animats

David Gibbs <dagibbs@qnx.com> wrote:

Robert Krten <> rk@parse.com> > wrote:

So. Here’s a business opportunity for you, John > :slight_smile: > Fax or call me with your
credit card number, and I’ll ship books to you at full retail. You can make
$BIGBUX$ on Amazon with them. To reorder, just send me an email. It’ll be
just like online ordering. > :slight_smile: > (Why don’t I do this myself? You need a US
mailing address to take part in the Amazon “slightly used books” reselling
scam.)

Rent a po-box accross the border? The drive to Kingston/Cornwall
once-a-week to check mail/mail stuff out shouldn’t be too bad,
should it?

Time == money :slight_smile: Driving time, border hassles, gas… nah.

I extend the business opportunity invite to anyone :slight_smile: Interested, Dave?

Cheers,
-RK

[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

Robert Krten <rk@parse.com> wrote:

So. Here’s a business opportunity for you, John > :slight_smile: > Fax or call me with your
credit card number, and I’ll ship books to you at full retail. You can make
$BIGBUX$ on Amazon with them. To reorder, just send me an email. It’ll be
just like online ordering. > :slight_smile: > (Why don’t I do this myself? You need a US
mailing address to take part in the Amazon “slightly used books” reselling
scam.)

Rent a po-box accross the border? The drive to Kingston/Cornwall
once-a-week to check mail/mail stuff out shouldn’t be too bad,
should it?

-David

QNX Training Services
http://www.qnx.com/services/training/
Please followup in this newsgroup if you have further questions.

I have yet to hear a successful defence for making less money. > :slight_smile:

How about happyness? How about making other things in life then money?

Or in your case maybe the simple pleasure you get when you say “screw
Amazon” :slight_smile:

  • Mario

Mario Charest <nowheretobefound@8thdimension.com> wrote:


I have yet to hear a successful defence for making less money. > :slight_smile:

How about happyness? How about making other things in life then money?

Or in your case maybe the simple pleasure you get when you say “screw
Amazon” > :slight_smile:

All of the above :slight_smile:

Yes, there are other things in life other than money (and perhaps we should
take that to qnx.cafe); I should have been clearer in the original post:
“I have yet to hear a successful defence for making less money FOR THE
SAME AMOUNT OF EFFORT”. I have heard successful defences for making less
money (i.e., you are less stressed).

Cheers,
-RK


[If replying via email, you’ll need to click on the URL that’s emailed to you
afterwards to forward the email to me – spam filters and all that]
Robert Krten, PDP minicomputer collector http://www.parse.com/~pdp8/

David Gibbs <dagibbs@qnx.com> wrote:

Robert Krten <> rk@parse.com> > wrote:

So. Here’s a business opportunity for you, John > :slight_smile: > Fax or call me with your
credit card number, and I’ll ship books to you at full retail. You can make
$BIGBUX$ on Amazon with them. To reorder, just send me an email. It’ll be
just like online ordering. > :slight_smile: > (Why don’t I do this myself? You need a US
mailing address to take part in the Amazon “slightly used books” reselling
scam.)

Rent a po-box accross the border? The drive to Kingston/Cornwall
once-a-week to check mail/mail stuff out shouldn’t be too bad,
should it?

I don’t think you HAVE TO do that. There are companies who will
manage those po-boxes for you and forward to you. (Is that called
forward service?). The $BIGBUX$ of one book sale will probably
cover the annual cost of the forward service :slight_smile:

Go Robert go !