powered by simpleCommunicator - 2.0.59     © 2026 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Unix-системы [игнор отключен] [закрыт для гостей] / кругом одни зомби
4 сообщений из 4, страница 1 из 1
кругом одни зомби
    #32667662
Фотография Новый Год
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Environment -- POSIX.1. z/OS блин.
псевдокод:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
int listen(void)
{
    
    
    for (;;)
    {

       ...... програмка ждет
       ...... как дождется, запустает процесс

        int forkrc = fork();
        
        switch (forkrc)
        {
            case   0 :
                system()  -- именно system, фича блин. 
                return  0 ;
                
            case - 1 :
                perror("fork");
                return - 1 ;
                break;
            default:
                cerr <<  flush;
                continue;
                break;
        }
    }
}

int main(int argc, char *argv[])
{
    ..................
    
    int rc = pipe(pfd); 
    if ( 0  != rc) 
    {
        perror("pipe");
        return  1 ;
    }
    
    rc = fork();
    switch (rc)
    {
        case  0 :
            close(pfd[ 0 ]);
            rc = dup2(pfd[ 1 ],  2 );
            rc = dup2(pfd[ 1 ],  1 );
            rc = listen();
            close( 1 );
            close( 2 );
            close(pfd[ 1 ]);  
            return rc;
            break;
            
        case - 1 : 
            perror("fork");
            return  1 ;
            break;
            
        default:
            close(pfd[ 1 ]);
            for (;;)
            {
                char ch;
                int len;
                len = read(pfd[ 0 ], &ch, sizeof(ch));
                if (sizeof(ch) == len)
                {
                    cout <<  ch << flush;
                }
                else
                {
                    return  0 ;
                }
            }
            break;
    }
    
    return  0 ;
}

я запускаю программку, она радостно работает. потом, вываливаетя на fork(), resource unavaible. смотрим reason - максимальное количество процессов для пользователя превышено. смотрим процессы - а там кругом одни зомби.
status -- Z Canceled and parent has not performed wait (Z for zombie).
Canceled and parent has not performed wait -- голая правда. я и не хочу его ждать блин.

вопрос - а как сделать, чтоб процесс все-таки сдох, что там в posix натисано:)
...
Рейтинг: 0 / 0
кругом одни зомби
    #32667724
Hoвый Год
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
вспомнил!!!


sigaction
sigaction() — Examine or Change a Signal Action
Standards
Format
#define _POSIX_SOURCE
#include <signal.h>
int sigaction(int sig,const struct sigaction Vnew, struct sigaction Vold);
General Description
Examines and changes the action associated with a specific signal.
int sig is the number of a recognized signal. sigaction() examines and sets the
action to be associated with this signal. Refer to Table 33 on page 1335 for the
values of sig, as well as the signals supported by OS/390 UNIX services. The sig
argument must be one of the macros defined in the signal.h header file.
const struct sigaction *new may be a NULL pointer. If so, sigaction() merely
determines the action currently defined to handle sig. It does not change this
action. If new is not NULL, it should point to a sigaction structure. The action
specified in this structure becomes the new action associated with sig.
struct sigaction *old points to a memory location where sigaction() can store a
sigaction structure. sigaction() uses this memory location to store a sigaction
structure describing the action currently associated with sig. old can also be a
NULL pointer, in which case sigaction() does not store this information.
This function is supported only in a POSIX program. See “OS/390 C/C++
Applications with OS/390 UNIX C/C++ Functions” on page 11 for more
information.
Special Behavior for C++
The behavior when mixing signal-handling with C++ exception handling is
undefined. Also, the use of signal-handling with constructors and destructors
is undefined.
C++ and C language linkage conventions are incompatible, and therefore
sigaction() cannot receive C++ function pointers. If you attempt to pass a C++
function pointer to sigaction(), the compiler will flag it as an error. Therefore,
to use the sigaction() function in the C++ language, you must ensure that
signal handler routines established have C linkage, by declaring them as
extern "C".
Signals
Standards / Extensions C or C++ Dependencies
POSIX.1
XPG4
XPG4.2
both POSIX(ON)
MVS 4.3
1334 OS/390 V2R10.0 C/C++ Run-Time Library Reference
sigaction
Table 33 (Page 1 of 2). Signals
Value
Default
Action Meaning
SIGABND 1 Abend.
SIGABRT 1 Abnormal termination (sent by abort()).
SIGALRM 1 A timeout signal (sent by alarm()).
SIGBUS 1 Bus error (available only when running on MVS 5.2 or
higher).
SIGFPE 1 Arithmetic exceptions that are not masked, for example,
overflow, division by zero, and incorrect operation.
SIGHUP 1 A controlling terminal is suspended, or the controlling
process ended.
SIGILL 1 Detection of an incorrect function image.
SIGINT 1 Interactive attention.
SIGKILL 1 A termination signal that cannot be caught or ignored.
SIGPIPE 1 A write to a pipe that is not being read.
SIGPOLL 1 Pollable event occurred (available only when running on
MVS 5.2 or higher).
SIGPROF 1 Profiling timer expired (available only when running on
MVS 5.2 or higher).
SIGQUIT 1 A quit signal for a terminal.
SIGSEGV 1 Incorrect access to memory.
SIGSYS 1 Bad system call issued (available only when running on
MVS 5.2 or higher).
SIGTERM 1 Termination request sent to the program.
SIGTRAP 1 Internal for use by dbx or ptrace.
SIGURG 2 High bandwidth data is available at a socket (available
only when running on MVS 5.2 or higher).
SIGUSR1 1 Intended for use by user applications.
SIGUSR2 1 Intended for use by user applications.
SIGVTALRM 1 Virtual timer has expired (available only when running on
MVS 5.2 or higher).
SIGXCPU 1 CPU time limit exceeded (available only when running on
MVS 5.2 or higher). If a process runs out of CPU time and
SIGXCPU is caught or ignored, OE generates a SIGKILL.
SIGXFSZ 1 File size limit exceeded (available only when running on
MVS 5.2 or higher).
SIGCHLD 2 An ended or stopped child process (SIGCLD is an alias
name for this signal).
SIGDCE 2 Signal is used by DCE (available only when running MVS
5.1 or higher).
SIGIO 2 Completion of input or output.
SIGIOERR 2 A serious I/O error was detected. (When running on MVS
4.3, this signal is not supported by the kernel. It will be
mapped to SIGIO. An application that uses SIGIO and
SIGIOERR may have undesirable results. This limitation is
removed when running on MVS 5.1, as SIGIO and
SIGIOERR are both supported.)
Chapter 4. Part 3. Library Functions (continued) 1335
sigaction
The Default Actions in Table 33 on page 1335 are:
1 Normal termination of the process.
2 Ignore the signal.
3 Stop the process.
4 Continue the process if it is currently stopped. Otherwise, ignore the
signal.
If the main program abends in a way that is not caught or handled by the
operating system or application, OS/390 UNIX terminates the running application
with a KILL -9. If OS/390 UNIX gets control in EOT or EOM and the terminating
status has not been set, OS/390 UNIX sets it to appear as if a KILL -9 occured.
If a signal catcher for a SIGABND, SIGFPE, SIGILL or SIGSEGV signal runs as a
result of a program check or an ABEND, and the signal catcher executes a
RETURN statement, the process will be terminated.
sigaction Structure
The sigaction structure is defined as follows:
struct sigaction {
void (Vsa_handler)(int);
sigset_t sa_mask;
int sa_flags;
void (Vsa_sigaction)(int, siginfo_t V, void V);
};
The following are members of the structure:
void (V)(int) sa_handler
A pointer to the function assigned to handle the signal. The value of
this member can also be SIG_DFL (indicating the default action) or
SIG_IGN (indicating that the signal is to be ignored).
Special Behavior for XPG4.2:
This member and sa_sigaction are mutually exclusive of each other.
When the SA_SIGINFO flag is set in sa_flags then sa_sigaction is
used. Otherwise, sa_handler is used.
sigset_t sa_mask
A signal set identifies a set of signals that are to be added to the
signal mask of the calling process before the signal handling function
sa_handler or sa_sigaction (in XPG4.2) is invoked. For more on signal
Table 33 (Page 2 of 2). Signals
Value
Default
Action Meaning
SIGWINCH 2 Window size has changed (available only when running on
MVS 5.2 or higher).
SIGSTOP 3 A stop signal that cannot be caught or ignored.
SIGTSTP 3 A stop signal for a terminal.
SIGTTIN 3 A background process attempted to read from a controlling
terminal.
SIGTTOU 3 A background process attempted to write to a controlling
terminal.
SIGCONT 4 If stopped, continue.
1336 OS/390 V2R10.0 C/C++ Run-Time Library Reference
sigaction
sets, see “sigemptyset() — Initialize a Signal Mask to Exclude All
Signals” on page 1357. You cannot use this mechanism to block
SIGKILL or SIGSTOP. If sa_mask includes these signals, they will
simply be ignored; sigaction() will not return an error.
sa_mask must be set by using one or more of the signal set
manipulation functions: sigemptyset(), sigfillset(), sigaddset(), or
sigdelset()
int sa_flags
A collection of flag bits that affect the behavior of signals. The
following flag bits can be set in sa_flags:
SA_NOCLDSTOP
Tells the system not to issue a SIGCHLD signal when
child processes stop. This is relevant only when the sig
argument of sigaction() is SIGCHLD.

SA_NOCLDWAIT
Tells the system not to create 'zombie' processes when a
child process dies. This is relevant only when the sig
argument of sigaction() is SIGCHLD. If the calling
process subsequently waits for its children, and the
process has no unwaited for children that were
transformed into zombie processes, it will block until all
of its children terminate. The wait(), waitid(), or
waitpid() will fail and set errno to ECHILD.

SA_NODEFER
Tells the system to bypass automatically blocking this
signal when invoking a signal handler function.
_SA_OLD_STYLE
Tells the C runtime library to use ANSI signal delivery
rules, instead of POSIX rules. It is supported for
compatibility with applications that use signal() to set
signal action. (See “signal() — Handle Interrupts” on
page 1369.) For a description of ANSI and POSIX.1
signal delivery rules, find “Handling Error Conditions
and Signals” in OS/390 C/C++ Programming Guide.
SA_ONSTACK
Tells the system to use the alternate signal stack (see
“sigaltstack() — Set and/or Get Signal Alternate Stack
Context” on page 1353 or “sigstack() — Set and/or Get
Signal Stack Context” on page 1389) when invoking a
signal handler function. If an alternate signal stack has
not been declared, the signal handler function will be
invoked with the current stack.
SA_RESETHAND
Tells the system to reset the signal's action to SIG_DFL
and clear the SA_SIGINFO flag before invoking a signal
handler function (Note: SIGILL and SIGTRAP cannot be
automatically reset when delivered. However, no error
will be generated should this situation exist). Otherwise,
the disposition of the signal will not be modified on
entry to the signal handler.
...
Рейтинг: 0 / 0
кругом одни зомби
    #32670046
no-dashi
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
А не проще было написать вот так???

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
void chld_handler(int n) {
   int x
   wait(&x);
}

int main() {
   signal ( SIGCHLD, chld_handler );
   ...
}
...
Рейтинг: 0 / 0
кругом одни зомби
    #32670666
Фотография Новый Год
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
да, да. я так и сделал в конечном счете.

extern "C"
void sigchld_handler(int type)
{

int status;
wait(&status);
cerr << "wait: status=" << status << "\n" << flush;
}

struct sigaction info;
if (sigaction(SIGCHLD,NULL,&info) == –1)
{
perror("sigaction");
return 1;
}

info.sa_handler = sigchld_handler;
struct sigaction info1;

if (sigaction(SIGCHLD,&info,&info1) == –1)
{
perror("sigaction");
return 1;
}
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / Unix-системы [игнор отключен] [закрыт для гостей] / кругом одни зомби
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]