08-21-2006
Quote:
Originally Posted by jim mcnamara
I'm confused. Are you trying to call popen() against an already existing process?
Or is the process being created becoming a background process with no controlling terminal?
In either case popen will not work. As you know. You can test to see if popen is still working with a valid stream. popen returns a FILE *ptr, so you can call (on Linux) isastream(fileno(ptr)) or more generally ioctl(fileno(ptr), I_CANPUT,0). These will return errors approiately. Assuming I understand what you're asking...
You may also want to check out the isatty() function.
this is the situation...
dedicated server program which is a background process without any controlling terminal which forks another server instance to handle client requests...
in that the program handling a client request - it checks whether a particular process is running or not..
the command string is framed it and it is passed to the popen function call and it fails there...
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hello all,
How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename.
Any assistance is most appreciated.
Thanks,
Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
2. Shell Programming and Scripting
Hi,
In shell script when I use
script1 >> filelog
the echo statments of script1 gets printed in the filelog
but when I try to run script in background i.e,
script1 & >> filelog
nothing gets printed in the filelog.
Anybody knows whats going on here.
thanks (3 Replies)
Discussion started by: k_oops9
3 Replies
3. UNIX for Dummies Questions & Answers
How, can I hide background process's output? (5 Replies)
Discussion started by: zylwyz
5 Replies
4. Shell Programming and Scripting
Hello,
This has probably been answered in other forms, however I would like to confirm this statement before I use it in production. Will this syntax work for a background process?
echo "nohup server_process1 >/dir1/nohup.server_process1 2>&1 &" | ksh
Please advise. Thanks (1 Reply)
Discussion started by: jerardfjay
1 Replies
5. Shell Programming and Scripting
i gave a copy process in the background( to copy around 100GB) , while in progress, the session got terminated. when i relogged in and checked the destination folder the copying was in progress... how could it happen(copying) when the shell terminates??? :rolleyes: (2 Replies)
Discussion started by: vinod.thayil
2 Replies
6. UNIX for Dummies Questions & Answers
What I need to learn is how to use a script that launches background processes, and then kills those processes as needed.
The script successfully launches the script. But how do I check to see if the job exists before I kill it?
I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies
7. AIX
how to check the process running in background? how can i run a process in background? pls explain with commands (1 Reply)
Discussion started by: udtyuvaraj
1 Replies
8. Shell Programming and Scripting
Hi,
I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming.
So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies
9. Shell Programming and Scripting
Hi,
I have written a menu driven shell script in which as per the choice, I run the another script on background.
For eg:
1. get info
2)process info
3)modify info
All the operations have different scripts which i schedule in background using &.
However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies
10. Shell Programming and Scripting
Here is my test code
process = sp.Popen( + ,
bufsize=1,
universal_newlines=True,
stdout=sp.PIPE, stderr=sp.STDOUT,
cwd=src_home)
output, _ =... (2 Replies)
Discussion started by: ezee
2 Replies
LEARN ABOUT NETBSD
pclose
POPEN(3) BSD Library Functions Manual POPEN(3)
NAME
popen, pclose -- process I/O
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
FILE *
popen(const char *command, const char *type);
int
pclose(FILE *stream);
DESCRIPTION
The popen() function ``opens'' a process by creating an IPC connection, forking, and invoking the shell. Historically, popen was implemented
with a unidirectional pipe; hence many implementations of popen only allow the type argument to specify reading or writing, not both. Since
popen is now implemented using sockets, the type may request a bidirectional data flow. The type argument is a pointer to a null-terminated
string which must be 'r' for reading, 'w' for writing, or 'r+' for reading and writing. In addition if the character 'e' is present in the
type string, the file descriptor used internally is set to be closed on exec(3).
The command argument is a pointer to a null-terminated string containing a shell command line. This command is passed to /bin/sh using the
-c flag; interpretation, if any, is performed by the shell.
The return value from popen() is a normal standard I/O stream in all respects save that it must be closed with pclose() rather than fclose().
Writing to such a stream writes to the standard input of the command; the command's standard output is the same as that of the process that
called popen(), unless this is altered by the command itself. Conversely, reading from a ``popened'' stream reads the command's standard
output, and the command's standard input is the same as that of the process that called popen().
Note that output popen() streams are fully buffered by default.
The pclose() function waits for the associated process to terminate and returns the exit status of the command as returned by wait4().
RETURN VALUES
The popen() function returns NULL if the fork(2), pipe(2), or socketpair(2) calls fail, or if it cannot allocate memory.
The pclose() function returns -1 if stream is not associated with a ``popened'' command, if stream has already been ``pclosed'', or if
wait4(2) returns an error.
ERRORS
The popen() function does not reliably set errno.
SEE ALSO
sh(1), fork(2), pipe(2), socketpair(2), wait4(2), fclose(3), fflush(3), fopen(3), shquote(3), stdio(3), system(3)
STANDARDS
The popen() and pclose() functions conform to IEEE Std 1003.2-1992 (``POSIX.2'').
HISTORY
A popen() and a pclose() function appeared in Version 7 AT&T UNIX.
BUGS
Since the standard input of a command opened for reading shares its seek offset with the process that called popen(), if the original process
has done a buffered read, the command's input position may not be as expected. Similarly, the output from a command opened for writing may
become intermingled with that of the original process. The latter can be avoided by calling fflush(3) before popen().
Failure to execute the shell is indistinguishable from the shell's failure to execute command, or an immediate exit of the command. The only
hint is an exit status of 127.
The popen() argument always calls sh(1), never calls csh(1).
BSD
June 24, 2011 BSD