Dear friends,
We are learning UNIX system programming as part of our course. I came across this simple program, which the teacher didn't explain well enough. could you please explain this program fully
And why does this program give an output of 912???
Thanks
Your program is calling printf(("%d\n",pid) from only one location (and from the if() block where its testing for the value of pid only after the expression pid = fork() is evaluated); so no mixture output, a simplest case of such fork() examples.
Who is executing that if() block ???. Its the parent (remind that fork() is a system call returns two times after a single call to it and it returns the parent (the callee to fork()) with the process id of the child it just created and a zero to that child. Hence that if() block is being executed by the parent only and its printing the process id it had received and collected in the variable pid of your program.
The output is just the process id of the child process created.
Can somebody explain to me the differences between fork() and vfork() system calls using C programs which I can implement in the UNIX environement? (1 Reply)
if
then
echo "Syntax: $0 <sid> <COLD/HOT> <DEST>"
exit
fi
if --------------what does this mean???
echo "Syntax: $0 <sid> <COLD/HOT> <DEST>"---pls explain this as well (2 Replies)
hi all i have an example i want one help me to understand cause i tried to test it but almost fail and i don't know how can i solve this problem " the main idea to read from two files and replace something from one to another " but i don't understand why it fail all time
$ cat main.txt... (4 Replies)
I'm trying to follow a script and I see it begins with this:
if ; then
if ; then
print "blah $0 blah blah "
exit
fi
fi
What does $# mean? I found out that $1 refers to the shell environment and the last argument that was entered or passed in the previous command. I couldn't find $#... (2 Replies)
Can someone do me a favour and explain the following for me:
((r=$RANDOM%$n+1))
I know what $RANDOM does but what is % sign and what does it do with %$n+1? (2 Replies)
Hi friends! I'm learning UNIX and I have a small question. Working with Shell, i put the name of one executable (in c language) + one number and it says this:
$ gcc misterioso_4.c
$ ./misterioso_4 6
got: ,
I can not find an answer in the manual because I havent applied any variable.... (5 Replies)