Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a big application (in C++), which generates from time to time defunct process. I know the application intensively uses linux commands inside. I would need to know which linux commands were called by those defunct sh process, is it possible to find out? Or, is it possible to set up Linux and get a sort of log when my application calls Linux commands?

Thanks.
Luke

share|improve this question

2 Answers 2

From Wikipedia:

A defunct process is a process that has completed execution but still has an entry in the process table. This entry is still needed to allow the process that started the (now zombie) process to read its exit status.

Is your C++ code calling wait()? If you get the exit status by calling wait() the defunct process should disappear.

share|improve this answer

This big application is issuing external commands via a shell, using popen or similar library functions. The intermediate shells remain as zombies (“defunct processes”) because the application isn't calling wait to “reap” its children. Note that zombie processes are totally harmless (no matter what B-movies might lead you to believe); the only resource they consume is an entry in the process table.

You can trace what commands the application executes by running

strace -f -s99999 -v -eexecve -o big-application.strace ./big-application

This may slow down your program somewhat. You can switch tracing on and off during the lifetime of a process: to start tracing, run

strace -f -s99999 -v -eexecve -o big-application.strace -p 12345

where 12345 is the process ID you want to trace. Kill the strace process (e.g. by pressing Ctrl+C) to stop tracing.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.