Sponsored Content
Top Forums UNIX for Advanced & Expert Users Doubt with fork() system call Post 302577885 by techmonk on Wednesday 30th of November 2011 07:35:59 AM
Old 11-30-2011
The final else part in your code will execute for the condition, when flag is not equal to -1, so this code is executed for the two conditions like when flag value is zero and when the flag value is pid of child.
In order to avoid this ...
Code:
main()
{
      int flag;
      flag = fork();

      if( flag == -1 ) // ERROR
      {
            //Error Message
      }
      if ( flag == 0 ) // Child
      {
           //Do child stuff
      }
      if( flag > 0 )
      {
         //Do parent stuff
      }

}

Moderator's Comments:
Mod Comment Please use code tags!

Last edited by zaxxon; 11-30-2011 at 09:27 AM.. Reason: more fine code. zaxxon: code tags
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

URGENT Help required regarding the use of FORK system call

I desperately wanted one of the UNIX Gurus to help me resolve my problem asap(I have to deliver the code to the client by Monday 08-oct). I have a file with around 5 million records (50 lakhs). Now my original process was taking around 30 hours to read the complete file, process each and every... (4 Replies)
Discussion started by: kkumar1975
4 Replies

2. Programming

Fork() system call time?

One more question. How can i calculate the time that system needs to make fork() system call? I need to make it with times function but i really don't know how. :( (2 Replies)
Discussion started by: davidoff
2 Replies

3. UNIX for Dummies Questions & Answers

fork() system call

Can anyone explain me what really happens when a system call fork() is called ? I like to know what happens internally. Thanks in Advance. - Arun (1 Reply)
Discussion started by: arunviswanath
1 Replies

4. UNIX for Dummies Questions & Answers

fork system call

Hi folks, I want to know how this below program works? #include <stdio.h> int main() { printf("A\n"); fork(); printf("B\n"); fork(); fork(); printf("D\n"); fork(); printf("C\n"); } This is just for example. How this type of programs where fork is used many places, how the... (1 Reply)
Discussion started by: u_peerless
1 Replies

5. Shell Programming and Scripting

Function call with argument doubt

Hi all, I am having a problem with user defined function call. I am new into the concept of shell script UDFs. My function is: iterate_directory() { cd $1 k=0 for i in * do if then ARR=${i} fi done echo ${ARR } } (4 Replies)
Discussion started by: canishk
4 Replies

6. Homework & Coursework Questions

fork system call understanding

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: i have a problem in understanding the behaviour of fork . i understood fork as to create a new process and... (4 Replies)
Discussion started by: MrUser
4 Replies

7. Shell Programming and Scripting

fork system call and \n

hi, i tried the following source codes: fork1.c: main() { printf("demo of fork\n"); fork(); printf("hello"); } output: demo of fork hello hello fork2.c: main() { printf("demo of fork"); (0 Replies)
Discussion started by: pnirmala
0 Replies

8. Programming

Problem with execution of fork system call if i use \n

hi all, i tried the following source codes: fork1.c: main() { printf("demo of fork\n"); fork(); printf("hello"); } output: demo of fork hello hello fork2.c: main() (3 Replies)
Discussion started by: pnirmala
3 Replies

9. Shell Programming and Scripting

Help: how to call fork() in shell script? New to linux

Hi, I'm writing a shell script where I want to call fork(). However I wrote like this "var=fork()" in c style and got this error: "syntax error near unexpected token `(' " How could I call fork() in shell script? Thanks in advance. Duplicate Post - Continue Here - Please Do Not Cross Post... (0 Replies)
Discussion started by: Xiaoya
0 Replies

10. Ubuntu

Help: how to call fork() in shell script? New to linux

Hi, I'm writing a shell script where I want to call fork(). However I wrote like this "var=fork()" in c style and got this error: "syntax error near unexpected token `(' " How could I call fork() in shell script? Thanks in advance. (2 Replies)
Discussion started by: Xiaoya
2 Replies
GLGETERROR(3G)							  [FIXME: manual]						    GLGETERROR(3G)

NAME
glGetError - return error information C SPECIFICATION
GLenum glGetError(void); DESCRIPTION
glGetError returns the value of the error flag. Each detectable error is assigned a numeric code and symbolic name. When an error occurs, the error flag is set to the appropriate error code value. No other errors are recorded until glGetError is called, the error code is returned, and the flag is reset to GL_NO_ERROR. If a call to glGetError returns GL_NO_ERROR, there has been no detectable error since the last call to glGetError, or since the GL was initialized. To allow for distributed implementations, there may be several error flags. If any single error flag has recorded an error, the value of that flag is returned and that flag is reset to GL_NO_ERROR when glGetError is called. If more than one flag has recorded an error, glGetError returns and clears an arbitrary error flag value. Thus, glGetError should always be called in a loop, until it returns GL_NO_ERROR, if all error flags are to be reset. Initially, all error flags are set to GL_NO_ERROR. The following errors are currently defined: GL_NO_ERROR No error has been recorded. The value of this symbolic constant is guaranteed to be 0. GL_INVALID_ENUM An unacceptable value is specified for an enumerated argument. The offending command is ignored and has no other side effect than to set the error flag. GL_INVALID_VALUE A numeric argument is out of range. The offending command is ignored and has no other side effect than to set the error flag. GL_INVALID_OPERATION The specified operation is not allowed in the current state. The offending command is ignored and has no other side effect than to set the error flag. GL_INVALID_FRAMEBUFFER_OPERATION The framebuffer object is not complete. The offending command is ignored and has no other side effect than to set the error flag. GL_OUT_OF_MEMORY There is not enough memory left to execute the command. The state of the GL is undefined, except for the state of the error flags, after this error is recorded. When an error flag is set, results of a GL operation are undefined only if GL_OUT_OF_MEMORY has occurred. In all other cases, the command generating the error is ignored and has no effect on the GL state or frame buffer contents. If the generating command returns a value, it returns 0. If glGetError itself generates an error, it returns 0. COPYRIGHT
Copyright (C) 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/. [FIXME: source] 05/30/2012 GLGETERROR(3G)
All times are GMT -4. The time now is 04:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy