Shanpei Zhou
Shanpei Zhou

Reputation: 391

Status of linux process when core dumping

Let's say I have a process which will generate a huge core file if it crashes somehow (e.g mysql). I want to know what's the status of the process when it core dumping. Is it as before or changing to zombie?

My real life problem is like this: I have a monitor to check the status of a process. Once it realizes the process crashes(by monitoring the status of the process), it will do something. I want to make sure the monitor do something only after core dumping finished. That's why I want to know the process status when core dumping.

Upvotes: 2

Views: 2472

Answers (1)

If your monitor is starting the processes with fork it should able to get SIGCHLD signals then call waitpid(2). AFAIK waitpid will tell you when the core dumping has finished (and won't return successfully before that)

Read also core(5)

Perhaps using inotify(7) facilities on the directory containing the core dump might help.

And systemd might be relevant too (I don't know the details)

BTW, while core dumping, I believe that the process status (as reported thru proc(5) in 3rd field of /proc/$PID/stat) is

       D  Waiting in uninterruptible disk sleep

So if you are concerned about long core dump time you could for example loop every half-second to fopen then fscanf then fclose that /proc/$PID/stat pseudo-file till the status is no more D

At last, core dumps are usually quick (unless you run on a supercomputer with a terabyte of RAM) these days (on Linux with a good file system like Ext4 or BTRFS), because I believe that (if you have sufficient RAM) the core dump file stays in the page cache. Core dumps lasting half an hour were common in the previous century on supercomputers (Cray) of that time.

Of course you could also stat(2) the core file.

See also http://www.linuxatemyram.com/

Upvotes: 2

Related Questions