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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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/*
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?
man proc
> 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?
What is the nohup flag??? First head of..
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

obgAuthor Commented:
> What is the nohup flag??? First head of..
Well, I'll counter... man nohup ;-)
I know the command nohup - but there is no such process flag like nohup.
obgAuthor Commented:
Ok... Then whatever nohup does (please tell me since I'm very curious), I want to be able to do (and undo).
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.
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?
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.

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

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?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.