Getting Mono runtime running Processes
After testing some code and using:
Proccess[] Proc =Process.GetProcessesByName("mono");
I finally reached an exception with his stacktrace:
Unhandled Exception: System.NotImplementedException: The requested feature is not implemented.
at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotImplementedException: The requested feature is not implemented.
at System.Diagnostics.Process.get_SessionId () [0x00000] in <filename unknown>:0
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_SessionId ()
at ProcWatch.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0
The request feature is not implemented. So it is not possible to recover mono children processes using the .NET framework. I am doing it by using a shell command:
Process.Start("/bin/bash"," -c 'ps -aux | grep Watcher'");
How to kill Linux properly C#
Using Process.Kill() is not a recommended way of stopping a process. It effectively sends the SIGKILL signal which unceremoniously terminates the process. By using the pkill
command with just the process name or kill
command with the PID (process identifier) you will politely ask the process in question to stop by sending it the SIGTERM signal. For more information on SIGTERM and SIGKILL please see https://www.gnu.org/software/libc/manual/html_node/Termination-Signals.html.
In short for your use case a good option is to do the following.
Process.Start("/bin/bash", " -c 'sudo pkill -f process_name'");
It will nicely ask the process to stop. If the process doesn't end, you can then resort to using:
Process.Kill();
How can I list all processes got executed during a shell-script(or sth. like that) running
You can use strace
in order to find all programs that were executed while your script was running. Something like this:
strace -o executed.txt -e execve -f sh your-sctrip.sh
This is an example. First my bash script:
$ cat build.sh
#!/bin/sh
g++ main.cpp
ls
Then strace of it:
$ strace 2>&1 -e execve -f bash build.sh \
| sed -n -r "s/.* execve\(\"([^,\"]+)\".* = 0$/\1/p"
/usr/local/CC/gcc-4.3.3/bin/g++
/usr/local/CC/gcc-4.3.3/libexec/gcc/x86_64-unknown-linux-gnu/4.3.3/cc1plus
/usr/bin/as
/usr/local/CC/gcc-4.3.3/libexec/gcc/x86_64-unknown-linux-gnu/4.3.3/collect2
/usr/bin/ld
/bin/ls
Or if you need only filenames add xargs -n 1 basename
:
$ strace 2>&1 -e execve -f bash build.sh \
| sed -n -r "s/.* execve\(\"([^,\"]+)\".* = 0$/\1/p" \
| xargs -n 1 basename
g++
cc1plus
as
collect2
ld
ls
Intermittent SIGSEV (segfault), SIGABORT and process hangs in C# code using Mono
Ok, it's a known bug in the kernel of Ubuntu.
There is a report bug on Xamarin: https://bugzilla.xamarin.com/show_bug.cgi?id=29827
So if you update your kernel on those machines the bug should go away (let's hope).
Cheers!
Related Topics
Script to Check for Process & Restart Program If Not Found
Perf Tool Stat Output: Multiplex and Scaling of "Cycles"
R Package Installation in Linux
How to Move First Column to Last Column in Unix
I'm Having Difficulty Understanding the Shellshock Vulnerability Verification
How to Increase Openfabrics Memory Limit for Torque Jobs
What Is Segment 00 in My Linux Executable Program (64 Bits)
How to Extract Patterns Form a Text Files in Shell Bash
Get and Use a Password with Special Characters in Bash Shell
Can Libpcap Reassemble Tcp Segments
How to Make My .Bat File Run Linux Command to Remote Linux
Linux Split a Column into Two Different Columns in a Same CSV File
How to Display Filename from a Column Using Awk
Docker Overlay2: Error Walking File System: Oserror [Errno 40] Too Many Levels of Symbolic Links
Ha Proxy Simple Forwarding with Docker
Find Files in Multiple Directories Taken from List in a File