08-01-2011
From a C programme?
If so, have a look at the man pages for these:
popen() if you need to send input to the command, or read output back from the command; be advised that with popen() you can only read or only write.
system() if you just need to execute a command. You'll get the exit code back, but no output.
fork() with exec() and possibly pipe() if you need absolute control over everything or need bidirectional communication with the child process.
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
I ask this question since sometimes i run a time-consuming ftp in foreground and forget to use nohup ftp.sh & to put this work background and can still running after i log off.
Assume this ftp task have run 1 hour, and still 1 hour time to end,
i don't want to abort the ftp, first, i use ctrl+Z... (3 Replies)
Discussion started by: stevensxiao
3 Replies
2. Programming
Hi All,
The scenario is like this:
There is a process say "A" which create a child process say "B" if some condition is true and process "A" terminates. "B" invokes some C program say "C" using 'execl' function. The job of program "C" is to keep polling the server until the server will be up.... (2 Replies)
Discussion started by: ranjkuma692
2 Replies
3. Shell Programming and Scripting
hi
what is the shell programming code to know the number of processes currently running on the machine & information about those processes.
Another one is the configuration and usage of the UNIX file system?
requesting all for help.
thanks (1 Reply)
Discussion started by: moco
1 Replies
4. UNIX for Dummies Questions & Answers
Hi all,
When I issued command ps -ef|grep Vinay in a UNIX machine,
I got the following
Vinay 22491 1 255 Jun 18 ? 294248:53 -sh
Vinay 26628 1 255 Jun 18 ? 294237:33 -sh
Could you tell me what all process is running ? Please explain each of the fields.
Thanks... (4 Replies)
Discussion started by: coolbhai
4 Replies
5. Shell Programming and Scripting
Hello all,
I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted.
Thanks in advance
Regards,
pradeep kulkarni.
:mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies
6. Shell Programming and Scripting
I'm trying to create a ksh script to do the following:
1) Ask the user what process they want to search for.
2) Have the script read the input as a variable and use it to search for the process.
3) Display the current time & date, the working directory of the process, and finally display the... (6 Replies)
Discussion started by: seekryts15
6 Replies
7. Shell Programming and Scripting
All,
1.What is the unix comand used for all current running process (Including All current running processes Parent ->child->subchild process)
2.If child and subchild processes are running then what is the unix command to kill parent and its all child subchild processes in UNIX.
Kindly... (7 Replies)
Discussion started by: skp
7 Replies
8. Shell Programming and Scripting
Hi,
i need to list the processes running only under current logged in user.
EX:
$ whoami
oraaqw
$ ps -ef | grep tnslsnr
oraaqw 11403300 19267592 0 09:14:47 pts/3 0:00 grep tnslsnr
oraaqw 15794208 1 0 Jan 14 - 11:59... (6 Replies)
Discussion started by: aravindadla
6 Replies
9. BSD
Hi Experts,
I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state.
On doing cat /proc/<pid>wchan showing the "__init_begin" in the output.
Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies
10. Shell Programming and Scripting
Team,
I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list.
How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies
POPEN(3) BSD Library Functions Manual POPEN(3)
NAME
pclose, popen -- process I/O
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdio.h>
FILE *
popen(const char *command, const char *mode);
int
pclose(FILE *stream);
DESCRIPTION
The popen() function ``opens'' a process by creating a bidirectional pipe, forking, and invoking the shell. Any streams opened by previous
popen() calls in the parent process are closed in the new child process. Historically, popen() was implemented with a unidirectional pipe;
hence, many implementations of popen() only allow the mode argument to specify reading or writing, not both. Because popen() is now imple-
mented using a bidirectional pipe, the mode argument may request a bidirectional data flow. The mode argument is a pointer to a null-termi-
nated string which must be 'r' for reading, 'w' for writing, or 'r+' for reading and writing.
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; it returns the exit status of the command, as returned by wait4(2).
RETURN VALUES
The popen() function returns NULL if the fork(2) or pipe(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 already ``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), wait4(2), fclose(3), fflush(3), fopen(3), stdio(3), system(3)
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() function always calls sh(1), never calls csh(1).
HISTORY
A popen() and a pclose() function appeared in Version 7 AT&T UNIX.
Bidirectional functionality was added in FreeBSD 2.2.6.
BSD
May 3, 1995 BSD