Oren Laadan [[email protected]] wrote:
|
| Suka,
|
| can you please post the entire test program so I can try to reproduce
| it here ?
Sure. Attached.
Suka
#include <stdio.h>
#include <unistd.h>
#include <wait.h>
#include <errno.h>
#define NUM_PROCS 10
#define CKPT_READY "ckpt-ready"
#define CKPT_DONE "ckpt-done"
#define TEST_DONE "test-done"
#define LOG_FILE "log.ptree1"
FILE *logfp;
void do_exit(int status)
{
if (logfp) {
fflush(logfp);
fclose(logfp);
}
_Exit(status);
}
int test_done()
{
int rc;
rc = access(TEST_DONE, F_OK);
if (rc == 0)
return 1;
else if (errno == ENOENT)
return 0;
fprintf(logfp, "access(%s) failed, %s\n", TEST_DONE, strerror(errno));
do_exit(1);
}
int checkpoint_done()
{
int rc;
rc = access(CKPT_DONE, F_OK);
if (rc == 0)
return 1;
else if (errno == ENOENT)
return 0;
fprintf(logfp, "access(%s) failed, %s\n", CKPT_DONE, strerror(errno));
do_exit(1);
}
void checkpoint_ready()
{
int fd;
fd = creat(CKPT_READY, 0666, 0);
if (fd < 0) {
fprintf(logfp, "creat(%s) failed, %s\n", CKPT_READY,
strerror(errno));
do_exit(1);
}
close(fd);
}
do_child(int cnum)
{
int i;
FILE *cfp;
char cfile[256];
sprintf(cfile, "child-log-%d", cnum);
i = 0;
while (!test_done()) {
cfp = fopen(cfile, "a");
if (!cfp) {
fprintf(logfp, "fopen(%s) failed, error %s\n", cfile,
strerror(errno));
do_exit(1);
}
fprintf(cfp, "i = %d\n", i++);
fflush(cfp);
fclose(cfp);
sleep(1);
}
do_exit(0);
}
print_exit_status(int pid, int status)
{
fprintf(logfp, "Pid %d unexpected exit - ", pid);
if (WIFEXITED(status)) {
fprintf(logfp, "exit status %d\n", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
fprintf(logfp, "got signal %d\n", WTERMSIG(status));
} else {
fprintf(logfp, "stopped/continued ?\n");
}
}
main(int argc, char *argv[])
{
int i;
int status;
int pid_list[NUM_PROCS];
if (test_done()) {
printf("Remove %s before running test\n", TEST_DONE);
do_exit(1);
}
logfp = fopen(LOG_FILE, "w");
if (!logfp) {
fprintf(stderr, "fopen(%s) failed, %s\n", LOG_FILE,
strerror(errno));
fflush(stderr);
do_exit(1);
}
close(0);close(1);close(2);
for (i = 0; i < NUM_PROCS; i++) {
if ((pid_list[i] = fork()) == 0)
do_child(i);
}
/*
* Now that we closed the special files and created process tree
* tell any wrapper scripts, we are ready for checkpoint
*/
checkpoint_ready();
while(!checkpoint_done())
sleep(1);
for (i = 0; i < NUM_PROCS; i++) {
if (waitpid(pid_list[i], &status, 0) < 0) {
fprintf(logfp, "waitpid(%d) failed, error %s\n",
pid_list[i], strerror(errno));
}
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
print_exit_status(pid_list[i], status);
}
}
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel