Hi,
Can we capture the stdout of another process, given only the pid of
that running process ?
Thanks in advance,
Gopu.
|
|
0
|
|
|
|
Reply
|
gopugopu
|
10/15/2003 2:38:35 PM |
|
gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> Can we capture the stdout of another process, given only the pid of
> that running process ?
It's possible but not trivial. I did a little experiment and ran
"cat", without any arguments. I attached to that cat process with gdb
and redirected its stdout to a file. I suppose you could do use named
pipes to read the output in a different process. Still, there might be a
much better way, for all I know.
What exactly is it you want to accomplish?
--
M�ns Rullg�rd
mru@users.sf.net
|
|
0
|
|
|
|
Reply
|
mru
|
10/15/2003 2:47:37 PM
|
|
gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> Can we capture the stdout of another process, given only the pid of
> that running process ?
If it's running in an X environment I believe there's some way of
getting the server to give you the i/o of a window, or so I've been
told.
If that's the case, try asking this in an X programming newsgroup.
Joe
|
|
0
|
|
|
|
Reply
|
joe
|
10/15/2003 4:23:16 PM
|
|
mru@users.sourceforge.net (M�ns Rullg�rd) wrote in message news:<yw1x7k36sgl2.fsf@users.sourceforge.net>...
> gopugopu@rediffmail.com (Gopu Bhaskar) writes:
>
> > Can we capture the stdout of another process, given only the pid of
> > that running process ?
>
> It's possible but not trivial. I did a little experiment and ran
> "cat", without any arguments. I attached to that cat process with gdb
> and redirected its stdout to a file. I suppose you could do use named
> pipes to read the output in a different process. Still, there might be a
> much better way, for all I know.
>
> What exactly is it you want to accomplish?
In the system in which I am working on many processes are started at
bootup. The printfs output dont come into any console. I was planning
to write a program which would capture the outputs of those printfs to
our console window.
something like `capture <pid>`, on running this we should be able to
see the printf outputs of the process with id pid.
Hope I am clear.
|
|
0
|
|
|
|
Reply
|
gopugopu
|
10/16/2003 7:22:28 AM
|
|
gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> mru@users.sourceforge.net (M�ns Rullg�rd) wrote in message
> news:<yw1x7k36sgl2.fsf@users.sourceforge.net>...
> > gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> >
> > > Can we capture the stdout of another process, given only the pid
> > > of that running process ?
> >
> > It's possible but not trivial. I did a little experiment and ran
> > "cat", without any arguments. I attached to that cat process with
> > gdb and redirected its stdout to a file. I suppose you could do
> > use named pipes to read the output in a different process. Still,
> > there might be a much better way, for all I know.
> >
> > What exactly is it you want to accomplish?
>
> In the system in which I am working on many processes are started at
> bootup. The printfs output dont come into any console. I was
> planning to write a program which would capture the outputs of those
> printfs to our console window.
If you have control over the boot process, just wrap the executables
in scripts which redirect the output before exec-ing the
programs. Then call the wrapper scripts from inittab or wherever.
Joe
|
|
0
|
|
|
|
Reply
|
joe
|
10/16/2003 1:36:44 PM
|
|
Gopu Bhaskar wrote:
> mru@users.sourceforge.net (M�ns Rullg�rd) wrote in message news:<yw1x7k36sgl2.fsf@users.sourceforge.net>...
>
>>gopugopu@rediffmail.com (Gopu Bhaskar) writes:
>>
>>What exactly is it you want to accomplish?
>
>
> In the system in which I am working on many processes are started at
> bootup. The printfs output dont come into any console. I was planning
> to write a program which would capture the outputs of those printfs to
> our console window.
>
> something like `capture <pid>`, on running this we should be able to
> see the printf outputs of the process with id pid.
>
> Hope I am clear.
You might want to try using a system call tracer like strace or truss
(depending on the system) to do this. You could wrap it in an awk
script if you need a particular format.
Having said that, if you have any control over development of those
programs you should have them use syslog rather than writing to stdout.
Syslog is the utility specifically designed to allow daemons to
report information in the form you are looking for. It also gives you
considerable configuration control over where the logged information
goes. See the man pages for syslog, syslogd and syslog.conf
-- ced
--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
|
|
0
|
|
|
|
Reply
|
Chuck
|
10/16/2003 2:02:09 PM
|
|
On Thu, 16 Oct 2003 13:36:44 GMT
joe@invalid.address wrote:
> gopugopu@rediffmail.com (Gopu Bhaskar) writes:
>=20
> > mru@users.sourceforge.net (M=E5ns Rullg=E5rd) wrote in message
> > news:<yw1x7k36sgl2.fsf@users.sourceforge.net>...=20
> > > gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> > >=20
> > > > Can we capture the stdout of another process, given only the pid
> > > > of that running process ?
> > >=20
> > > It's possible but not trivial. I did a little experiment and ran
> > > "cat", without any arguments. I attached to that cat process with
> > > gdb and redirected its stdout to a file. I suppose you could do
> > > use named pipes to read the output in a different process. Still,
> > > there might be a much better way, for all I know.
> > >=20
> > > What exactly is it you want to accomplish?
> >=20
> > In the system in which I am working on many processes are started at
> > bootup. The printfs output dont come into any console. I was
> > planning to write a program which would capture the outputs of those
> > printfs to our console window.
>=20
> If you have control over the boot process, just wrap the executables
> in scripts which redirect the output before exec-ing the
> programs. Then call the wrapper scripts from inittab or wherever.
Many Unix/Linux systems use startup scripts usually located in
/etc/init.d or /sbin/init.d or /etc/rc.d/init.d. These scripts also may
set up how these daemons log their messages. And some are just started
with output redirected to /dev/null. And, some do write to the console.
You may even be able to grab some of the output via the dmesg(8)
command.=20
But, as M=E5ns mentioned, if you really need to capture the the output of
an already running program, it is non-trivial and non-portable.=20
--=20
Jerry Feldman <gaf-nospam-at-blu.org>
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
|
|
0
|
|
|
|
Reply
|
Jerry
|
10/16/2003 2:11:11 PM
|
|
joe@invalid.address wrote in message news:<m3brshz4my.fsf@invalid.address>...
> gopugopu@rediffmail.com (Gopu Bhaskar) writes:
>
> > mru@users.sourceforge.net (M�ns Rullg�rd) wrote in message
> > news:<yw1x7k36sgl2.fsf@users.sourceforge.net>...
> > > gopugopu@rediffmail.com (Gopu Bhaskar) writes:
> > >
> > > > Can we capture the stdout of another process, given only the pid
> > > > of that running process ?
> > >
> > > It's possible but not trivial. I did a little experiment and ran
> > > "cat", without any arguments. I attached to that cat process with
> > > gdb and redirected its stdout to a file. I suppose you could do
> > > use named pipes to read the output in a different process. Still,
> > > there might be a much better way, for all I know.
> > >
> > > What exactly is it you want to accomplish?
> >
> > In the system in which I am working on many processes are started at
> > bootup. The printfs output dont come into any console. I was
> > planning to write a program which would capture the outputs of those
> > printfs to our console window.
>
> If you have control over the boot process, just wrap the executables
> in scripts which redirect the output before exec-ing the
> programs. Then call the wrapper scripts from inittab or wherever.
>
> Joe
The system on which i am working cannot be rebooted. Seems like
filtering the truss output would be the best option. I will continue
investigting....
|
|
0
|
|
|
|
Reply
|
gopugopu
|
10/20/2003 8:01:15 AM
|
|
|
7 Replies
491 Views
(page loaded in 0.283 seconds)
Similiar Articles: Capture the stdout of another process. - comp.unix.programmer ...Hi, Can we capture the stdout of another process, given only the pid of that running process ? Thanks in advance, Gopu. ... How does a scrpt find its process id when under cron ? - comp.unix ...Capture the stdout of another process. - comp.unix.programmer ..... to see the printf outputs of the process with id ... email when no stdout/stderr from script - comp ... Capturing output of os.system to a string - comp.lang.python ...Capture the stdout of another process. - comp.unix.programmer ... Many Unix/Linux systems use startup scripts ... E5ns mentioned, if you really need to capture the the ... nohup, redirection and splitting stderr and stdout - comp.unix ...Capture the stdout of another process. - comp.unix.programmer ... nohup, redirection and splitting stderr and stdout - comp.unix ... Capture the stdout of another process ... manually flush stdout pipe? - comp.unix.shellCapture the stdout of another process. - comp.unix.programmer ... manually flush stdout pipe? - comp.unix.shell Capture the stdout of another process. - comp.unix ... How to test if stdout == stderr? - comp.unix.programmerCapture the stdout of another process. - comp.unix.programmer ... Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... Here's the hypothetical scenario: I ... Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ...Capture the stdout of another process. - comp.unix.programmer ... Redirect stderr/stdout to a file using SetStdHandle - comp.os.ms ... Capture the stdout of another ... question about execl(), fork(), stdin, stdout, stderr - comp.unix ...Capture the stdout of another process. - comp.unix.programmer ... question about execl(), fork(), stdin, stdout, stderr - comp.unix ..... using the following call after I ... cron continues to email when no stdout/stderr from script - comp ...Capture the stdout of another process. - comp.unix.programmer ... cron continues to email when no stdout/stderr from script - comp ... Capture the stdout of another ... Capturing SP Output In Shell Script - comp.unix.questions ...Capture the stdout of another process. - comp.unix.programmer ... Capturing SP Output In Shell Script - comp.unix.questions ... Capture the stdout of another process ... Capture the stdout of another process. - comp.unix.programmer ...Hi, Can we capture the stdout of another process, given only the pid of that running process ? Thanks in advance, Gopu. ... capture child process STDOUT/STDERR on Win32Comment on capture child process STDOUT/STDERR on Win32 Re: capture child process STDOUT/STDERR on Win32 by Anonymous Monk on Jul 28, 2008 at 09:25 UTC 7/20/2012 3:17:09 PM
|