Kill Zombie Process Via C Program Without Killing Main Process

Hi ,
In my program, for a process A executing operation, there are multiple threads created.
One of the thread A checks whether process is active or not
Second thread B executes a function
One of the periodic thread C calls a callback function that executes an audit after every 30 secs.

In the audit , the function uses g_spawn_commmand_line_sync() function to spawn a child process that executes a command line (shell script).

Since g_spawn_commmand_line_sync() spawns a new child process .
In the error case scenario, the spawned child process got stuck and became zombie process. It did not get killed.Also it acquired sockets which were assigned to a thread B executing operation.

Even though the thread B got terminated ,the child process did not release the sockets that were connected to it.


My question is ,I have to automate this in C program that if it finds spawned process of g_spawn_commmand_line_sync() defunct, the
health check thread B should be able to clean it without klling the main process.

i could not find any spawn function that will help me find the PID of g_spawn_commmand_line_sync() spawned process.

I get the details from ps commands. But how can I find it in a c-program?


Similar Content



Watching / Capturing An Applications Threads

There is a home grown application that initiates either a telnet or ssh session based on the number of threads set.

I want to watch the process happen from start to finish, that is from the moment the first thread starts until the last thread finishes.

I was thinking netstat, but it wont show the process in its entirety. As connections are established and terminated the status / output of the command would be different..not to mention Id have to keep hitting the command and the enter key.

As usual, I have cracked my Linux in a nutshell book and will be doing web searches to find a solution.

Difference Between Child THREAD And Child PROCESS

Hello,

I am troubleshooting something and I got this problem.

If I do "pstree -p"

It shows,

Code:
        ├─soffice.bin(7734)─┬─{soffice.bin}(7735)
        │                   ├─{soffice.bin}(7736)
        │                   ├─{soffice.bin}(7737)
        │                   └─{soffice.bin}(7743)

However, it does NOT show up in "ps -elf"

Code:
ps -elf | grep soffi
0 S whho      7734     1  0  80   0 - 36435 -      11:14 pts/2    00:00:03 /usr/lib/openoffice/program/soffice.bin -splash-pipe=5
0 S whho      7833  7759  0  80   0 -   751 -      11:21 pts/3    00:00:00 grep soffi

I was wondering if 7735, 7736, 7737, 7743 were really processes. Then I checked /proc, I could cd to /proc/7735, /proc/7736, etc, but I could not ls them out.

I looked at the man page of "pstree", it says,

Code:
Child threads  of a process are found under the parent process and are shown with the process name in curly braces, e.g.

           icecast2---13*[{icecast2}]

So, what does all this mean? Does it mean that 7735, 7736, 7737, 7743 are just threads but not processes? If so, why could I cd to /proc/<id> but not see them in "ps -elf".

Would somebody please help me?

Thanks!

whho

How To Share The Same Code Segment Between Two Processes Using Mmaps?

Hi Experts:

I'm new to Linux,recently i was confused with the words as below:

"To achieve sharing,the process A mmaps the executable file of process B into into the virtual address space of process A. As the Linux loader maps the executable files into the process when executing them,the two processes share the memory image of the mapped file"

questions:
1,What are the "executable files",are they ELF files?
2,How to do "mmaps"?if process A and process B share the same code segment, ,where is process A's own code segment?


Thank you in advance.

Linux Process Call Examles

hi all
i am new to linux system programming.
request u to give idea with examples for linux process creation fork() and exec setsig() setalarm(). how to catch these process id's

Regards
Bala

Kill -3 Pid > /tmp/process.txt Not Working?

Hi All,
I am trying to get a dump of a process using kill and it doesn't look to be working, can someone explain what I am doing wrong?

Code:
systemctl start snmpd.service

Code:
pgrep snmpd
4233

Code:
kill -3 4233 > /tmp/snmp_pid.txt

OR

Code:
kill -SIGQUIT 4233 > /tmp/snmp_pid.txt

Yes the process quit's which is fine but there is no output from the process in /tmp/snmp_pid.txt.

Can someone please explain?

Thanks

What Is Context Switching

I'm currently reading Brian Wards book: How Linux Works: What Every Superuser Should Know 2nd edition and I'm confused about step 3 in the context of the other steps:
1. The CPU (the actual hardware) interrupts the current process based on an internal timer, switches into kernel mode, and hands control back to the kernel.

2. The kernel records the current state of the CPU and memory, which will be essential to resuming the process that was just interrupted.

3. The kernel performs any tasks that might have come up during the preceding time slice (such as collecting data from input and output, or I/O, operations).

4. The kernel is now ready to let another process run. The kernel analyzes the list of processes that are ready to run and chooses one.

5. The kernel prepares the memory for this new process, and then prepares the CPU.

6. The kernel tells the CPU how long the time slice for the new process will last.

7. The kernel switches the CPU into user mode and hands control of the CPU to the process.

What does he mean preceding time slice as surely the tasks have been completed during the time slice in steps 1-2?

Process Vs Task Vs Threads

can anyone explain me the exact difference between process task and threads??
thanks in advance!!!

Equivalent Command For "time -v" In Centos

I want to know the approximate maximum memory usage by my process. If I start the process using "time -v <myprocess>", I get the output after it terminates. This works fine in RedHat Enterprise Linux, but not in Centos. There does not seem to be an option "-v" for time. Do I miss anything ? What is the equivalent in Centos to know the peak memory usage by a process ?

Scripts To Respond To Prompts

I have searched and was unsuccessful in finding a quick command or example to use.

I'm looking to automate an update process using command line in Debian.
Normally I'd use apt-get update|upgrade|dist-upgrade .

If apt-get finds a package to update it queries a Y/n response.
My objective is to have a script determine if this prompt is there, and if so to respond with 'Y'.
If not then it should not enter a response.

I know I'll need to use an IF/ELSE function, but what I'm having difficulties locating is to read the output of apt-get .

I know there's books and sites available, but they are all long and sometimes difficult to read or understand. And maybe my keywords are the right ones to use, as I'm not able to pinpoint a solution.

Thanks for your assistance.

How To Read The Signal Queue Of A Process??

Hi,

I am not completely new to linux.

My problem is the following:

The signal queue of my process gets filled with time.

With /proc/PID/status --> SigQ 6032/6032 i can see that the queue is full!

And my software is waiting on signals to process data. So I want to know wich signal filled my queue and I am interested to see the attached data of the signal --> sival_int or sival_ptr, I use sigwaitinfo() to read the data.