![]() |
| | #1 |
| subminimalist Join Date: Jul 2008 Location: NYC
Posts: 3,946
| fork() question Code: #include <stdio.h>
int main() {
short int pid, i;
for (i=0; i<=1; i++) {
pid = fork();
if (pid==0) printf("hello%d\n",i);
else printf("pid: %d\n", pid);
fflush(NULL);
}
}
Code: hello0 hello1 pid: 4790 pid: 4789 hello1 pid: 4791
__________________ Accuracy and integrity mean nothing if you don't make it past the censors...PYTHAGORAS |
| MK27 is offline | |
| | #2 |
| Registered User Join Date: Oct 2001
Posts: 2,110
| fork returns a pid_t, not a short int. To print a short int, use %hd. #include <unistd.h> for fork. >fflush(NULL); *sad face* |
| robwhit is offline | |
| | #3 |
| and the hat of vanishing Join Date: Aug 2001 Location: The edge of the known universe
Posts: 21,214
| The first child process doesn't exit, so it too runs a loop with i = 1
__________________ If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut. Up to 8Mb PlusNet broadband from only £5.99 a month! |
| Salem is offline | |
![]() |
| Tags |
| fork |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A small question about fork( ) | mlhazan | C Programming | 4 | 08-13-2008 08:18 PM |
| fork() question | cstudent | C Programming | 3 | 04-25-2008 06:48 AM |
| Question sorting character arrays: C programming | NeoSigma | C Programming | 3 | 05-23-2003 09:28 PM |
| Fork() child process question | CrackDown | Linux Programming | 0 | 04-17-2003 11:58 AM |
| opengl DC question | SAMSAM | Game Programming | 6 | 02-26-2003 09:22 PM |