I have my inputfile in the following format :
From:sdhfhg
dsfhsdjfjdsfh
dsfjdjshjsd
djfhsdjfjsdhjds
Error Description
<aa.aa.aa.aa.aa.aa>
From:ksljfsdhfjh
djfdsjkf
sdjwoquk
dsfsdfj
Error Description
<dd.dd.dd.dd.dd>
I want to read the lines from tag 'From:' thrul <aa.aa.aa.aa.aa.aa>... (1 Reply)
Hello experts,
I am using fork() in my code but I am confused which output comes first child or parent?
I did the following code .My book shows parent first but my linux shows child first.Can anyone tell me why?
#include <stdio.h>
int main(){
int pid;
printf("I am original process with pid... (5 Replies)
Assume we have an application built on *nix that uses fork()...then the processes procedure is going to act as follow:
X is considered a parent process (first click on application)
Y is considered a child process of X (second click on application)
Z is considered a child process of Y (third... (6 Replies)
hi,
i start using awk and have a very basic problem. here's my code:
#! /usr/bin/awk -f
# 2010, scz
#
{
$1 == "test" { print $2 }
}
this works on the command line but not as "program" - what is the difference between awk programs on the command line and executing awk... (3 Replies)
I writing a program that forks three times but only on the parent process. The three children processes then produces output in order. 1, 2, 3. I am confused on how to do this. I have tried multiple if and else if statements but the output does not come out right. How should I go about doing this? (1 Reply)
Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine.
So, i want to... (1 Reply)
i'm experimenting fork function and i found this code
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <wait.h>
#include <fcntl.h>
#include <unistd.h>
int main(void)
{
int fd;
pid_t p;
p = fork();
fork();
if (p>0) { fork();}
fork();
fork();... (6 Replies)
Hi All,
I have a program for class that needs to do the following:
1. Print the directory entries from the current directory using ncurses
2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file
3. Execute those commands in... (1 Reply)
Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck
What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies
LEARN ABOUT OPENSOLARIS
p2close
p2open(3GEN) String Pattern-Matching Library Functions p2open(3GEN)NAME
p2open, p2close - open, close pipes to and from a command
SYNOPSIS
cc [ flag ... ] file ... -lgen [ library ... ]
#include <libgen.h>
int p2open(const char *cmd, FILE *fp[2]);
int p2close(FILE *fp[2]);
DESCRIPTION
The p2open()gfunction forks and execs a shell running the command line pointed to by cmd. On return, fp[0] points to a FILE pointer to
write the command's standard input and fp[1] points to a FILE pointer to read from the command's standard output. In this way the program
has control over the input and output of the command.
The function returns 0 if successful; otherwise, it returns -1.
The p2close() function is used to close the file pointers that p2open() opened. It waits for the process to terminate and returns the
process status. It returns 0 if successful; otherwise, it returns -1.
RETURN VALUES
A common problem is having too few file descriptors. The p2close() function returns -1 if the two file pointers are not from the same
p2open().
EXAMPLES
Example 1 Example of file descriptors.
#include <stdio.h>
#include <libgen.h>
main(argc,argv)
int argc;
char **argv;
{
FILE *fp[2];
pid_t pid;
char buf[16];
pid=p2open("/usr/bin/cat", fp);
if ( pid == -1 ) {
fprintf(stderr, "p2open failed
");
exit(1);
}
write(fileno(fp[0]),"This is a test
", 16);
if(read(fileno(fp[1]), buf, 16) <=0)
fprintf(stderr, "p2open failed
");
else
write(1, buf, 16);
(void)p2close(fp);
}
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|MT-Level |Unsafe |
+-----------------------------+-----------------------------+
SEE ALSO fclose(3C), popen(3C), setbuf(3C), attributes(5)NOTES
Buffered writes on fp[0] can make it appear that the command is not listening. Judiciously placed fflush() calls or unbuffering fp[0] can
be a big help; see fclose(3C).
Many commands use buffered output when connected to a pipe. That, too, can make it appear as if things are not working.
Usage is not the same as for popen(), although it is closely related.
SunOS 5.11 29 Dec 1996 p2open(3GEN)