fucking system programming
1
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
2
Name:
Anonymous
2009-03-07 14:32
only losers and grannies still use C
sage
3
Name:
Anonymous
2009-03-07 14:39
Only losers and grannies still use sage.
Sage.
4
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.
5
Name:
Anonymous
2009-03-07 14:42
6
Name:
Anonymous
2009-03-07 14:47
>>4
My guess is that he forgot to call fork(), not getpid().
7
Name:
Anonymous
2009-03-07 14:49
>>6
My guess is that he's a fucktard.
8
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.
9
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
10
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.
11
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
12
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.
13
Name:
Anonymous
2009-03-07 17:48
int main(void){
if(!fork()) for(pid_t pid; pid = fork(););
return 0;
}
14
Name:
Anonymous
2009-03-07 17:56
"pid"
15
Name:
Anonymous
2009-03-07 17:58
>>14
congratulations on your successful utilization of the
[code] tag
16
Name:
Anonymous
2009-03-07 17:59
>>15
I believe you are looking for /pr/
17
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.
18
Name:
Anonymous
2009-03-07 18:47
19
Name:
Anonymous
2009-03-07 19:11
Just use the motherfucking goddamn Erlang already!! (!)
20
Name:
Anonymous
2009-03-07 20:25
>>16
Где /pr/? Я не знаю...
21
Name:
Anonymous
2009-03-07 20:27
>>16
lol, but 7chan is down. That's what they get for running a continuation of Kusaba.
22
Name:
Anonymous
2009-03-07 20:30
>>20
ITT мы не говорим русская язык
23
Name:
Anonymous
2009-03-07 20:44
pid_t pid;
if (pid<0)
lolwut
24
Name:
Anonymous
2009-03-07 20:58
лолшто
25
Name:
Anonymous
2009-03-07 22:51
for has two return values ◔ヮ◔ isn't that amazing?
26
Name:
Anonymous
2009-03-07 23:08
>>25
No. Learn about continuations. Also,
_exit has no return value .
27
Name:
Anonymous
2009-03-08 5:32
There is no spoon().
28
Name:
Anonymous
2009-03-08 8:29
WHY THE FUCK CAN'T YOU PEOPLE READ MAN PAGES?
29
Name:
Anonymous
2009-03-08 9:06
pid not initialized?
30
Name:
Anonymous
2009-03-08 11:28
"GRUNNA
31
Name:
Anonymous
2009-03-08 12:43
"
32
Name:
Anonymous
2009-03-08 14:35
>>27
there used to be one but people kept
spoon()ing child processes.
33
Name:
Anonymous
2009-03-08 14:42
while (1)
spork();
34
Name:
Anonymous
2009-03-08 15:06
(while (1)
(hold-up (*spork*))
35
Name:
Anonymous
2009-03-08 15:15
>>33,34
#include <t3hPeNgU1NoFd00m.h>
36
Name:
Anonymous
2009-03-08 15:25
37
Name:
Anonymous
2009-03-08 15:30
unsafePerformSpork
38
Name:
Anonymous
2009-03-08 15:46
>>33
you're doing it wrong.
it's
void spoon(pid_t).
39
Name:
Anonymous
2009-03-09 6:45
I can't import invader zim for spork(); halp
40
Name:
Anonymous
2009-03-09 7:02
Hello Zim, welcome to SporkHack! You are a chaotic male Irken Invader.
41
Name:
Anonymous
2009-03-09 8:26
*holds up spork*
42
Name:
2010-10-26 11:06