Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

fucking system programming

Name: Anonymous 2009-03-07 14:13

Explain me this;

int main (int argc, const char * argv[])
{       
    pid_t pid;
   
    if (pid<0)
    {
        printf("epic fail\n");
        return 1;
    }
    else if (pid ==0)
    {
        printf("omg child process");
    }
    else
    {
        wait(NULL);
        //child complete if any
        printf("parent\n");
    }
    return 0;
}


when executed, you expect this to just say parent, as there is no fork (yet) - however, when I run it by compiling myself via gcc, I get epic fail (which obviously shouldn't happen), and if I do it via the automated compiler of xcode, which is just a front-end for gcc, I get "child process"

so basically I get the two responses I shouldn't be getting

WHAT THE FUCK IS THIS

HELP ME, /prog/ YOU'RE MY LAST RESORT

Name: Anonymous 2009-03-07 14:32

only losers and grannies still use C

sage

Name: Anonymous 2009-03-07 14:39

Only losers and grannies still use sage.

Sage.

Name: Anonymous 2009-03-07 14:39

Oh no, my boy, you forgot to call getpid() on your variable there. So basically pid is uninitialized, and in a comparison like the one you have, whatever value that memory was at will be read. It's a little unpredictable what will result, but getting a value less than zero is not unlikely here.

Call pid_t getpid(void) before you start checking it.

Hope that works for you.

Name: Anonymous 2009-03-07 14:42

>>4
YOU HELPED HIM!!!

Name: Anonymous 2009-03-07 14:47

>>4
My guess is that he forgot to call fork(), not getpid().

Name: Anonymous 2009-03-07 14:49

>>6
My guess is that he's a fucktard.

Name: Anonymous 2009-03-07 14:53

>>6
Could be right, honestly. It's been a while since I've had to do this.

I'm not sure fork() will give you the pid of the current process, though. Just the pid of the child is returned.

Name: Anonymous 2009-03-07 14:55

>>6
yeah, I forgot fork(), you're right

I actually expected no help from here so went digging in sample codes - thanks

Name: Anonymous 2009-03-07 14:57

>>8
In the parent processfork() gives you the pid of the child process created.
In the child process however fork() will return 0.

Name: Anonymous 2009-03-07 14:58

>>8
getpid() returns the pid of the process, but fork() gives 0 for the kiddy threads which was what I needed

Name: Anonymous 2009-03-07 14:59

>>10
Ah, ah, I was confused with what OP was trying to do.
Glad they got it though.

Name: Anonymous 2009-03-07 17:48

int main(void){
  if(!fork()) for(pid_t pid; pid = fork(););
  return 0;
}

Name: Anonymous 2009-03-07 17:56

"pid"

Name: Anonymous 2009-03-07 17:58

>>14
congratulations on your successful utilization of the [code] tag

Name: Anonymous 2009-03-07 17:59

>>15
I believe you are looking for /pr/

Name: Anonymous 2009-03-07 18:46

wow what a retard. if you couldnt see that fault you should be using or c, or any language for that matter.

Name: Anonymous 2009-03-07 18:47

>>17
IN BEFORE SHOULDNT

Name: Anonymous 2009-03-07 19:11

Just use the motherfucking goddamn Erlang already!! (!)

Name: Anonymous 2009-03-07 20:25

>>16
Где /pr/? Я не знаю...

Name: Anonymous 2009-03-07 20:27

>>16
lol, but 7chan is down. That's what they get for running a continuation of Kusaba.

Name: Anonymous 2009-03-07 20:30

>>20
ITT мы не говорим русская язык

Name: Anonymous 2009-03-07 20:44


pid_t pid;
if (pid<0)

lolwut

Name: Anonymous 2009-03-07 20:58

лолшто

Name: Anonymous 2009-03-07 22:51

for has two return values ◔ヮ◔ isn't that amazing?

Name: Anonymous 2009-03-07 23:08

>>25
No. Learn about continuations. Also, _exit has no return value.

Name: Anonymous 2009-03-08 5:32

There is no spoon().

Name: Anonymous 2009-03-08 8:29

WHY THE FUCK CAN'T YOU PEOPLE READ MAN PAGES?

Name: Anonymous 2009-03-08 9:06

pid not initialized?

Name: Anonymous 2009-03-08 11:28

"GRUNNA

Name: Anonymous 2009-03-08 12:43

"

Name: Anonymous 2009-03-08 14:35

>>27
there used to be one but people kept spoon()ing child processes.

Name: Anonymous 2009-03-08 14:42

while (1)
    spork();

Name: Anonymous 2009-03-08 15:06


(while (1)
  (hold-up (*spork*))

Name: Anonymous 2009-03-08 15:15

>>33,34
#include <t3hPeNgU1NoFd00m.h>

Name: Anonymous 2009-03-08 15:25

>>35
#include <random.h>

Name: Anonymous 2009-03-08 15:30

unsafePerformSpork

Name: Anonymous 2009-03-08 15:46

>>33
you're doing it wrong.
it's void spoon(pid_t).

Name: Anonymous 2009-03-09 6:45

I can't import invader zim for spork(); halp

Name: Anonymous 2009-03-09 7:02

Hello Zim, welcome to SporkHack!  You are a chaotic male Irken Invader.

Name: Anonymous 2009-03-09 8:26

*holds up spork*

Name: ​​​​​​​​​​ 2010-10-26 11:06

Name: Anonymous 2010-11-27 21:11

Name: Anonymous 2010-12-06 9:46

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List