01-03-2006
Hi
thanks for your attention
here I have written a sample code that works
only for one time I mean if I ommit the line exit(EXIT_SUCCESS) in default part the activity of
client never ends with the wrong output it means that only it printfs:
child: the name is %s !!
for unlimited times but when I use this line every thing is ok but just for one data just for
"afi" in array names and then every thing ends.
well what do you think about it ? what is my problem?
one another time thanks for your attention
Best Regards.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
static void sigchld_handler(int sig) { int stat; wait(&stat); }
int main()
{
char names[7][10]={"afi","shin","pedi","arin","nazin","mam","bab"};
int fd[2];
int nread;
int i,j,rc;
pid_t pid;
char buf[1024];
struct sigaction sigchldr;
memset(&sigchldr, 0, sizeof(struct sigaction));
sigchldr.sa_handler = sigchld_handler; sigaction(SIGCHLD, &sigchldr, NULL);
printf("\n start");
if ((rc=pipe(fd))<0)
{
printf("\n pipe error");
exit(0);
}
i=0;
while(i<7)
{
printf("\n enter while %d",i);
switch((pid=fork()))
{
case -1:
printf("\n fork error");
exit(EXIT_FAILURE);
case 0: //child
printf("\n child");
close(fd[1]);
while((nread=read(fd[0],buf,1024)!=0))
{
char c=getchar();
printf("\n child: the name is %s !!",buf);
}
close(fd[0]);
exit(EXIT_SUCCESS);
default: //parent
printf("\n parent");
char c=getchar();
close(fd[0]);
printf("\n strart parent %s",names[i]);
write(fd[1],names[i],1024);
printf("\n writing %s is finished $",names[i]);
close(fd[1]);
exit(EXIT_SUCCESS);
}
i++;
}
exit(EXIT_SUCCESS);
}
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I'm trying to understand if it's possible to create a set of variables that are numbered based on another variable (using eval) in a loop, and then call on it before the loop ends.
As an example I've written a script called question (The fist command is to show what is the contents of the... (2 Replies)
Discussion started by: DeCoTwc
2 Replies
2. Shell Programming and Scripting
Hi Im running this script, which is supposed to find the max value build some tables and then stop running once all the tables are built. Thing is , it keeps assigning a null value to $h and then $g is null so it keep building tables i.e. testupdateNUL. How can I stop this? Here is what I have:
... (4 Replies)
Discussion started by: brandono66
4 Replies
3. Shell Programming and Scripting
Hi all
Sorry for the basic question, but i am writing a shell script to get around a slightly flaky binary that ships with one of our servers. This particular utility randomly generates the correct information and could work first time or may work on the 12th or 100th attempt etc !.... (4 Replies)
Discussion started by: rethink
4 Replies
4. Shell Programming and Scripting
Hi All ,
Is there any way to replace the pipe ( | ) with the broken pipe (0xA6) in unix (1 Reply)
Discussion started by: saj
1 Replies
5. Shell Programming and Scripting
Hello All,
Maybe I'm Missing something here but I have NOOO idea what the heck is going on with this....?
I have a Variable that contains a PATTERN of what I'm considering "Illegal Characters". So what I'm doing is looping
through a string containing some of these "Illegal Characters". Now... (5 Replies)
Discussion started by: mrm5102
5 Replies
6. Shell Programming and Scripting
Hi guys,
I need to know how i can ignore Pipe '|' if Pipe is coming as a column in Pipe delimited file
for eg:
file 1:
xx|yy|"xyz|zzz"|zzz|12...
using below awk command
awk 'BEGIN {FS=OFS="|" } print $3
i would get xyz
But i want as :
xyz|zzz to consider as whole column... (13 Replies)
Discussion started by: rohit_shinez
13 Replies
7. Shell Programming and Scripting
Hi,
I want to read file multiple times. Right now i am using while loop but that is not working.
ex.
While read line
do
while read line2
do
echo stmt1
#processing some data based on data.,
done < file2.txt
done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies
8. Shell Programming and Scripting
Here's my code:
awk -F '' 'NR==FNR {
if (/time/ && $5>10)
A=$2" "$3":"$4":"($5-01)
else if (/time/ && $5<01)
A=$2" "$3":"$4-01":"(59-$5)
else if (/time/ && $5<=10)
A=$2" "$3":"$4":0"($5-01)
else if (/close/) {
B=0
n1=n2;
... (2 Replies)
Discussion started by: klane
2 Replies
9. Shell Programming and Scripting
Hi all,
i developed a script to measure the uptime of a process in a Solaris 10/11 environments.
All is well, but i came across a situation where there are multiple processes of the same name. Basically i have the following result file:
beVWARS 13357 19592122
beVWARS 14329 19591910... (4 Replies)
Discussion started by: nms
4 Replies
LEARN ABOUT CENTOS
bsd_signal
BSD_SIGNAL(3P) POSIX Programmer's Manual BSD_SIGNAL(3P)
PROLOG
This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the correspond-
ing Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.
NAME
bsd_signal - simplified signal facilities
SYNOPSIS
#include <signal.h>
void (*bsd_signal(int sig, void (*func)(int)))(int);
DESCRIPTION
The bsd_signal() function provides a partially compatible interface for programs written to historical system interfaces (see APPLICATION
USAGE).
The function call bsd_signal(sig, func) shall be equivalent to the following:
void (*bsd_signal(int sig, void (*func)(int)))(int)
{
struct sigaction act, oact;
act.sa_handler = func;
act.sa_flags = SA_RESTART;
sigemptyset(&act.sa_mask);
sigaddset(&act.sa_mask, sig);
if (sigaction(sig, &act, &oact) == -1)
return(SIG_ERR);
return(oact.sa_handler);
}
The handler function should be declared:
void handler(int sig);
where sig is the signal number. The behavior is undefined if func is a function that takes more than one argument, or an argument of a dif-
ferent type.
RETURN VALUE
Upon successful completion, bsd_signal() shall return the previous action for sig. Otherwise, SIG_ERR shall be returned and errno shall be
set to indicate the error.
ERRORS
Refer to sigaction().
The following sections are informative.
EXAMPLES
None.
APPLICATION USAGE
This function is a direct replacement for the BSD signal() function for simple applications that are installing a single-argument signal
handler function. If a BSD signal handler function is being installed that expects more than one argument, the application has to be modi-
fied to use sigaction(). The bsd_signal() function differs from signal() in that the SA_RESTART flag is set and the SA_RESETHAND is clear
when bsd_signal() is used. The state of these flags is not specified for signal().
It is recommended that new applications use the sigaction() function.
RATIONALE
None.
FUTURE DIRECTIONS
None.
SEE ALSO
sigaction(), sigaddset(), sigemptyset(), signal(), the Base Definitions volume of IEEE Std 1003.1-2001, <signal.h>
COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2003 Edition, Standard for Information Technol-
ogy -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE
and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained
online at http://www.opengroup.org/unix/online.html .
IEEE
/The Open Group 2003 BSD_SIGNAL(3P)