Sponsored Content
Top Forums Programming Reference Variables To A Child Process Created With Fork Post 8166 by AJAY BHATIA on Sunday 7th of October 2001 03:38:03 PM
Old 10-07-2001
Question Reference Variables To A Child Process Created With Fork

Hi!

IN THE FOLLOWING PROGRAM THE VALUE OF j REMAINS UNCHANGED . WHY ? IF I WANT A VARIABLE VALUE TO CHANGE LIKE THIS , IS THERE ANY WAY TO DO IT ?

Or do we have to use shared memory variables?

main()
{
int return_pid, i, total;
int j=1;
total = TOTALRECS+1;

for (i=0; i<NUMPROCESSES; i++)
if (fork() == 0)
child_code (i,total,&j);

for (i=0; i<NUMPROCESSES; i++)
return_pid = wait(0);

printf ("value of J <%d>\n", j);
}
 

10 More Discussions You Might Find Interesting

1. Programming

the scop of variables in child process

Hi I have a question about the scope of variables for parent and a child I had written my code here and the output of this but only in child process the information is completely right even in main the informatin is wrong well the child process will see the global variable te2 and can change... (5 Replies)
Discussion started by: netman
5 Replies

2. Programming

fork() with su (child with other user)

Hi all, i need to execute a program from within my c++ code. This is no problem. system(), fork(), execxy(). But now i want to able to execute the program as another user as the parent process. The whole thing is on solaris. I should be possible for both, users with no shell and no password... (1 Reply)
Discussion started by: heck
1 Replies

3. Programming

fork() and child processes

Hello, How many child processes are actually created when running this code ? #include <signal.h> #include <stdio.h> int main () { int i ; setpgrp () ; for (i = 0; i < 10; i++) { if (fork () == 0) { if ( i & 1 ) setpgrp () ; printf ("Child id: %2d, group: %2d\n", getpid(),... (0 Replies)
Discussion started by: green_dot
0 Replies

4. Shell Programming and Scripting

fork() and child processes

Hello, How many child processes are actually created when running this code ? #include <signal.h> #include <stdio.h> int main () { int i ; setpgrp () ; for (i = 0; i < 10; i++) { if (fork () == 0) { if ( i & 1 ) setpgrp () ; printf ("Child id: %2d, group: %2d\n",... (1 Reply)
Discussion started by: green_dot
1 Replies

5. Programming

Problems with child comunicating with parent on fork()

Hello, I'm trying to implement a version of a bucketSort (kinda) server/client, but I'm having a VERY hard time on making the server behave correctly, when talking to the children, after it forks. The server is kinda big (300+ lines), so I won't post it here, but here's what I'm doing. 1)create a... (8 Replies)
Discussion started by: Zarnick
8 Replies

6. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

7. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

8. Programming

fork(), parent and child processes???

Hi friends, I have a small question regarding unix system call fork, I hope you will solve my problem. Here is the small program $ cat fork1.c #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { int pid; int x = 0; x = x + 1; pid = fork(); if(pid < 0) {... (2 Replies)
Discussion started by: gabam
2 Replies

9. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

Hi everyone i am very new to linux , working on bash shell. I am trying to solve the given problem 1. Create a process and then create children using fork 2. Check the Status of the application for successful running. 3. Kill all the process(threads) except parent and first child... (2 Replies)
Discussion started by: vizz_k
2 Replies

10. Programming

Generating Random Number in Child Process using Fork

Hello All, I am stuck up in a program where the rand functions ends up giving all the same integers. Tried sleep, but the numbers turned out to be same... Can anyone help me out how to fix this issue ? I have called the srand once in the program, but I feel like when I call fork the child process... (5 Replies)
Discussion started by: manisum
5 Replies
pthread_condattr_getpshared(3T) 										   pthread_condattr_getpshared(3T)

NAME
pthread_condattr_getpshared(), pthread_condattr_setpshared() - get or set the process-shared attribute SYNOPSIS
PARAMETERS
attr Pointer to the condition variable attributes object whose process-shared attribute is to be set/retrieved. pshared This parameter either specifies the new value of the process-shared attribute (set function) or it points to the memory location where the process-shared attribute of attr is to be returned (get function). DESCRIPTION
The attributes object attr must have been previously initialized with the function before these functions are called. The functions are used to set and retrieve the process-shared attribute in a condition variable attributes object. The legal values for the process-shared attribute are: This option permits a condition variable to be operated upon by any thread that has access to the memory where the condition variable is allocated. The application is responsible for allocating the condition variable in memory that multiple processes can access. The condition variable can be operated on only by threads created within the same process as the thread that initialized the condition variable. If threads of differing processes attempt to operate on such condition variable, the behavior is undefined. The default value of process-shared is sets the process-shared attribute in attr. The new value of the process-shared attribute of attr is set to the value specified in the pshared parameter. retrieves the value of the process-shared attribute from attr. The value of the process-shared attribute of attr is returned in the pshared parameter. RETURN VALUE
Upon successful completion, and return zero. Otherwise, an error number is returned to indicate the error (the variable is not set). ERRORS
If any of the following occur, the and functions return the corresponding error number: is not defined and these functions are not supported. For each of the following conditions, if the condition is detected, the function returns the corresponding error number: attr is not a valid condition variable attributes object. The value specified by pshared is not a legal value. For each of the following conditions, if the condition is detected, the function returns the corresponding error number: The value specified by attr or pshared is invalid. WARNINGS
If a condition variable is created with the process-shared attribute defined as the cooperating processes should have access to the memory in which the condition variable is allocated. AUTHOR
and were derived from the IEEE POSIX P1003.1c standard. SEE ALSO
pthread_create(3T), pthread_condattr_init(3T), pthread_cond_init(3T), pthread_mutex_init(3T). STANDARDS CONFORMANCE
Pthread Library pthread_condattr_getpshared(3T)
All times are GMT -4. The time now is 06:30 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy