• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

Process control

What ways are there to control a process in runtime? I would like to tamper with the nohup flag, flush/inspect the I/O queues, etc.
0
obg
Asked:
obg
  • 6
  • 5
1 Solution
 
ravenplCommented:
You can try attaching to such process with gdb (or any other debugger).
However You may encounter such problem, that debug symbols are not compiled in(or stripped) and all You get would be memory addresses.
For less intrusive informations check /proc/PID/*
0
 
obgAuthor Commented:
I know a lot of information can be found in /proc/PID but that is read only, right? Besides, is there an explanation of the contents available somewhere?

Attaching through gdb might work, but I don't want to interrupt the process. - I guess I'll have to study gdb a little bit further. And of course the program is compiled without debug information. - Maybe I can recompile it and load the symbols from the new file...?

Still, I can't change the process flags (like nohup) from gdb, can I?
0
 
ravenplCommented:
man proc
> Maybe I can recompile it and load the symbols from the new file...?
Yes.

> Still, I can't change the process flags (like nohup) from gdb, can I?
What is the nohup flag??? First head of..
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
obgAuthor Commented:
> What is the nohup flag??? First head of..
Well, I'll counter... man nohup ;-)
0
 
ravenplCommented:
I know the command nohup - but there is no such process flag like nohup.
0
 
obgAuthor Commented:
Ok... Then whatever nohup does (please tell me since I'm very curious), I want to be able to do (and undo).
0
 
ravenplCommented:
nohup redirects stdin, stdout and stdin to file. Therefore while process is disconected from terminal, it still can read/write.
Then it sets SIGHUP handler to ignore.
0
 
obgAuthor Commented:
Yes. It's the SIGHUP handler I'm looking for (I think). I don't think it's necessary at this point, but can I manipulate the redirects as well?
0
 
ravenplCommented:
Normally You can't, but
If You run the process with some LD_PRELOAD'ed functions, then from within debugger You can execute the new function from any point of running process.
Those functions could set the SIGHUP handler to IGNORE or DEFAULT.
Same for fd switching (new function opens new file(newfd), dup2(newfd, 0), close(newfd))
But it's not easy.
0
 
MysidiaCommented:
This kind of control of a process during runtime isn't available from outside --- if you run "nohup program";
the behavior of nohup is not accomplished by a mere process flag.

It is nohup itself that is immune to hangups ---  nohup doesn't modify the program it starts, sets up the
environment in a certain way - and starts the program up in that environment.

There is no easy way to accomplish exactly what nohup does without either modifying the program to
include nohup's features, OR to have run nohup in the first place.

To run the process with some Preloaded functions, entails that you have modified the program...
since you have to arrange the preloading before the program starts, it's not something you
can use to change a program you already started.

You could have just run "nohup program" beforehand, if you knew in advance...


You can run GDB and attach it to a running process, with
gdb /path/to/program
(gdb) attach <pid>

Suppose the program's PID is 12345...
Within GDB you can possibly redirect output to a file  or set SIGHUP to ignore by doing something like

shell$ gdb /path/to/program
(gdb) attach 12345
(gdb) call signal(1,1)
(gdb) call freopen("nohup.out", "a", stdout);
(gdb) call freopen("nohup.out", "a", stderr);
(gdb) detach



And no, you will not be able to reverse it with any simple command;  once you have made
another file descriptor the standard output  output file, there's really no method of
ascertaining the original output destination.

0
 
obgAuthor Commented:
Ok. First part of my question is answered, I guess. How about the I/O queues? Can I (from gdb or anywhere else) see what has been written to stdout (primarily) and not yet been flushed? - Can I flush it from the outside?
0
 
obgAuthor Commented:
Sorry for the delay. I guess I wanted more input at the beginning... Anyway, ravenpl helped me a lot with this one, so I think he deserves the score.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now