Sponsored Content
Full Discussion: another qustion about fork
Top Forums Programming another qustion about fork Post 47036 by Perderabo on Sunday 1st of February 2004 09:41:14 PM
Old 02-01-2004
pid can be less than zero, equal to zero, or greater than zero. You already tested for equal to zero. And you tested for less than zero.

That means that pid must be greater than zero when it reaches that code. Putting in an explicit test will not change the way the program runs. And it will slow it down, but not measurably so.

Still I would put the explicit test in. This makes the code more readable. It also makes "paragraph 3" more self sufficient. These things make future changes to the program easier.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Fork

What is a fork? Why would one create a fork? What are the advantages and disadvantages of using a fork? Please advise. Thank You. Deepali (5 Replies)
Discussion started by: Deepali
5 Replies

2. UNIX for Dummies Questions & Answers

mailx and mail list help - newbie qustion

I have a basic question - how do I create and then use a mail list to be able to send a mailx email to multiple recipients. I assume I create a test file using vi, containing the email addresses - but what is the format - are the addresses separated by ";", or by spaces, ....??? Is there a... (1 Reply)
Discussion started by: HikerLT
1 Replies

3. Programming

fork()

#include <stdio.h> #include <string.h> #include <sys/types.h> #define MAX_COUNT 200 #define BUF_SIZE 100 void main(void) { pid_t pid; int i; char buf; fork(); pid = getpid(); for (i = 1; i <= MAX_COUNT; i++) { sprintf(buf,... (2 Replies)
Discussion started by: MKSRaja
2 Replies

4. Programming

Fork or what?

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)
Discussion started by: crippe
0 Replies

5. Programming

Fork ()

hi all About this code for (i = 1; i < n; i++) if ((childpid = fork()) <= 0) break; I really can't understand the output . and the way fork () return the value . how about the process Id ,the child process Id and the parent ID in this case so please answer me soon (5 Replies)
Discussion started by: iwbasts
5 Replies

6. Programming

fork() help

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)
Discussion started by: alexicopax
3 Replies

7. UNIX for Advanced & Expert Users

Fork and \n

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)
Discussion started by: xyz123456
1 Replies

8. Programming

Fork and \n

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)
Discussion started by: xyz123456
2 Replies

9. Programming

Fork()

does fork() spawn only the parent process, what if fork() is looped, does it spawn the parent and the child? (4 Replies)
Discussion started by: Peevish
4 Replies

10. UNIX for Dummies Questions & Answers

fork()

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)
Discussion started by: l flipboi l
1 Replies
shmx(8) 						      System Manager's Manual							   shmx(8)

Name
       shmx - shared memory exerciser

Syntax
       /usr/field/shmx [ -h ] [ -ofile ] [ -ti ] [ -mj ] [ -sk ] [ -v ]

Description
       The  memory exerciser spawns a background process and these two processes exercise the shared memory segments. They each take turns writing
       and reading the other's data in the segments.

       You can specify the number of memory segments to test and the size of the segment to be tested by and processes. The exerciser  runs  until
       the process receives a or a kill -15 pid.

       A  logfile  is  made in for you to examine and then remove. If there are errors in the logfile, check the file, where the driver and kernel
       error messages are saved.  The exerciser is automatically invoked when the exerciser is started.  You can also run by itself.

Options
       -h	 Print the help message for the command.

       -v	 Use the system call instead of to spawn

       -ofile	 Save diagnostic output in file.

       -ti	 Run time in minutes (i).  The default is to run until the process receives a or a kill -15 pid.

       -mj	 The memory segment size in bytes (j) to be tested by the processes.  Must be greater than 0.  The default is SMMAX/6.	(SMMAX	is
		 a system parameter set in the file

       -sk	 The number of memory segments (k).  The default is 6.	The maximum is also 6.

Examples
       The following example tests six memory segments (default), each with a segment size of SMMAX/6, until a or kill -15 pid is received:
       % /usr/field/shmx
       The following example runs three memory segments of size 100,000 bytes for 180 minutes in the background:
       % /usr/field/shmx -t180 -m100000 -s3 &

Restrictions
       If  there  is  a  need to run a system exerciser over an NFS link or on a diskless system there are some restrictions.  For exercisers that
       need to write into a file system, such as the target file system must be writable by root.  Also the directory, in which any of	the  exer-
       cisers  are  executed,  must be writable by root because temporary files are written into the current directory.  These latter restrictions
       are sometimes difficult to overcome because often NFS file systems are mounted in a way that prevents root from writing into them.  Some of
       the restrictions may be overcome by copying the exerciser to another directory and then executing it.

See Also
       Guide to System Exercisers

																	   shmx(8)
All times are GMT -4. The time now is 02:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy