your code would be more easily readable with tabs , to get them use the
[code]
code here
[/code]
this will look like this:
Anyway, it seems as though you are entering an infinite while loop "polling" the shared memory for a change in the child. Then you are writing back to the shared memory in said child for another to pick it up. This is all being done without any semaphore protection and therefore it is possible that things could go awry.
At any rate, this polling makes inefficient use of the CPU cycles, IMO. While it gets your assignment done...I just wanted to point out that its probably not an effective way of doing it.
However, it looks like you got it done...congrats.
edit: looks like the child does the shared memory write...this is worse yet.
Last edited by DreamWarrior; 04-19-2004 at 03:35 PM..
Dear all,
suppose that I start a process (named "father"). "father" starts in turns a process called "child" with an execv call (after a fork). In this way "father" will be notified if "chlid" crashes (SIGCHILD mechanism). The problem is:
if "father" crashes, how can I do to be recreate a... (1 Reply)
I don't follow what these are...
this is what my text says...
"When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)
Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?
Thanks (2 Replies)
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)
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)
All,
Ok...so I know I *should* be able to control a process's stdin and stdout from the parent by creating pipes and then dup'ing them in the child. And, this works with all "normal" programs that I've tried. Unfortunately, I want to intercept the stdin/out of the scp application and it seems... (9 Replies)
I have a .NET application that remotely starts, stops, and gets status of Windows services and scheduled tasks. I would like to add the capability of starting, stopping, and getting status of remote AIX applications also. Based on some preliminary research, one option may be to use 3rd party .NET... (0 Replies)
I am trying to implement the below using Ksh script on a Lx machine.
There is a file(input_file) with 100K records. For each of these records, certain script(process_rec) needs to be called with the record as input. Sequential processing is time-consuming and parallel processing would eat up... (2 Replies)
is there a universal way of getting the children of a particular process? i'm looking for a solution that works across different OSes...linux, aix, sunos, hpux.
i did a search online and i kept finding answers that were specific to Linux..i.e. pstree.
i want to be able to specify a process... (2 Replies)
Discussion started by: SkySmart
2 Replies
LEARN ABOUT MINIX
sem_init
SEM_INIT(3) Linux Programmer's Manual SEM_INIT(3)NAME
sem_init - initialize an unnamed semaphore
SYNOPSIS
#include <semaphore.h>
int sem_init(sem_t *sem, int pshared, unsigned int value);
Link with -pthread.
DESCRIPTION
sem_init() initializes the unnamed semaphore at the address pointed to by sem. The value argument specifies the initial value for the sem-
aphore.
The pshared argument indicates whether this semaphore is to be shared between the threads of a process, or between processes.
If pshared has the value 0, then the semaphore is shared between the threads of a process, and should be located at some address that is
visible to all threads (e.g., a global variable, or a variable allocated dynamically on the heap).
If pshared is nonzero, then the semaphore is shared between processes, and should be located in a region of shared memory (see shm_open(3),
mmap(2), and shmget(2)). (Since a child created by fork(2) inherits its parent's memory mappings, it can also access the semaphore.) Any
process that can access the shared memory region can operate on the semaphore using sem_post(3), sem_wait(3), and so on.
Initializing a semaphore that has already been initialized results in undefined behavior.
RETURN VALUE
sem_init() returns 0 on success; on error, -1 is returned, and errno is set to indicate the error.
ERRORS
EINVAL value exceeds SEM_VALUE_MAX.
ENOSYS pshared is nonzero, but the system does not support process-shared semaphores (see sem_overview(7)).
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+-----------+---------------+---------+
|Interface | Attribute | Value |
+-----------+---------------+---------+
|sem_init() | Thread safety | MT-Safe |
+-----------+---------------+---------+
CONFORMING TO
POSIX.1-2001.
NOTES
Bizarrely, POSIX.1-2001 does not specify the value that should be returned by a successful call to sem_init(). POSIX.1-2008 rectifies
this, specifying the zero return on success.
SEE ALSO sem_destroy(3), sem_post(3), sem_wait(3), sem_overview(7)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2017-09-15 SEM_INIT(3)