Hi friends,
First I am going to type the c program, then we will discuss it.
And here comes my questions
1. Why does
variable contain two values, or how could it have two values, less than 0, equal to 0, and greater than zero. They say fork() returns different values for parent process and child process. but how is it possible for one variable to hold two values at the same time?
2. Please explain the syntax of
. What does it get NULL at the end?
3. Syntax of exit()???. Somestimes it gets -1, 0 and EXIT_FAILURE and things like that.
4. What does wait() do, why is it taking NULL argument here?
And here is a another program
And it's output
1. Why and how there is a switching between child process and parent process?
2. What is the different between exit() and _exit()
And a small program as well,
And here is the output
Why does the second value, 1055 gets printed, I didn't use printf to print this value, where did it come from? And if I remove the printf function from this program, like
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
int main()
{
pid_t pid;
pid = fork();
return 0;
}
then there is no output at all, why is that so?
Please bear with my nonsensical questions, I am an absolute novice???
Did you take a look at the description/manpages of the functions you're asking about? There's a lot of useful information in there, and it'll help you asking more specific questions, which will yield more informative answers. Besides, the most important trait needed in IT is the ability to learn new things, and how to look up information.
I understand that fork create a child but I need very simple example that make child useful....
I mean how will make the program faster anyone explain with code plz
using C plz (2 Replies)
I'm trying to run a simple test on how to use fork(), i'm able to execute the child process first then the parent, but how can I execute parent then child..?
Thanks! (1 Reply)
Hi,
I wrote a simple program for understanding the fork command. The code is as below
int main(void)
{
fork(); printf("hi 1 \n");
fork(); printf("hi 2 \n");
fork(); printf("hi 3 \n");
}
I am getting a variation in the number of times the printf is called if i remove the \n from each... (2 Replies)
Hi,
I wrote a simple program for understanding the fork command. The code is as below
int main(void)
{
fork(); printf("hi 1 \n");
fork(); printf("hi 2 \n");
fork(); printf("hi 3 \n");
}
I am getting a variation in the number of times the printf is called if i remove the \n from each of... (1 Reply)
Hi everybody,
I wanna write a code to understand how fork works.
my target
--------------
-Parent creates a file(called temp) and writes into this file "1".Then it closes the file.
-Then parent creates a child and wait until execution of this child ends.
-Then child opens the same... (3 Replies)
Hello all.
I'm developing a filetransfer application, which is supposed to work sort of like dcc, with multiple transfers etc. Now i wonder what the best way to manage the transfers is. Should i fork() for each new transfer, hogging loads of memory or use pthreads? Maybe I can use select to see... (0 Replies)
I run this code, actually I want to both processes print the message from "data". But only one does. What happens? Anyone can help?
#include <stdio.h>
main(){
int fd, pid;
char x;
fd = open("data",0); /* open file "data" */
pid = fork();
if(pid != 0){
wait(0);
... (2 Replies)