Sponsored Content
Top Forums Programming C: Memory Fault (core dumped) Post 302815169 by ebasse2 on Friday 31st of May 2013 05:36:56 AM
Old 05-31-2013
C: Memory Fault (core dumped)

When I run programm show this message: Memory Fault (core dumped)

Does anyone can help me and tell me what is wrong? please

Code:
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

int main(int argc, char *argv[]) { 


    int i=0;
    int il_krok = atoi(argv[1]);
    
    for (i=0;i< il_krok; i++)
    {
        printf("\nProces matka: %d,PID: %d krok %d z %d\n",i+1,getpid(),i+1,il_krok);
        sleep(1);
    }

    int newPid;

    for (i=1;i<argc;i++)
    {
        newPid = fork();

        if (newPid == 0)
        {
            printf("PID nowego procesu potomnego: %d", getpid());

            int j=0;
            il_krok = atoi(argv[i+1]);

            for (j=0;j< atoi(argv[i+1]); j++)
            {
                printf("\nProces id: %d,PID: %d krok %d z %d\n",i+1,getpid(),j+1,il_krok);
                sleep(1);
            }

            return (i+1);

            int status = 0;
            int pid = wait(&status);

            printf("Proces zakonczony: PID: %d Status: %d \n",pid, WEXITSTATUS(status));
        }

        else
        {
            int status = 0;
            int pid = wait(&status);

            printf("Proces zakonczony: PID: %d Status: %d \n",pid, WEXITSTATUS(status));

        }

    }

    return EXIT_SUCCESS;
}

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Segmentation fault (core dumped)

Hello To All! Now anfd then I receive a message on my console: Segmentation fault (core dumped) What does it mean? Or more precisely what are the implications? :confused: (1 Reply)
Discussion started by: Ivo
1 Replies

2. Programming

Segmentation Fault (core dumped)

what r the situations to receive an error msg like the one below Segmentation Fault (core dumped) (2 Replies)
Discussion started by: bankpro
2 Replies

3. UNIX for Advanced & Expert Users

Memory Fault - Core Dumped

I use SCO UNIX 5.07 on a Compaq Proliant Machine. Each time I press the Escape or Delete key while running a program or issuing a FoxBase+ command from the dot prompt, I receive the error message: "Memory Fault - Core Dumped" and the screen locks up immediately. I would appreciate if necessary... (0 Replies)
Discussion started by: bayuz
0 Replies

4. Programming

Memory Fault,Core dumped

I have written a code in UNIX which is complied by using g++. Compling with turbo C didnt yield any errors, but with g++ I am getting Memory fault, core dumped. Could anyone help me out with this? Given below is the code: #include<stdio.h> #include<string.h> #include<stdlib.h>... (2 Replies)
Discussion started by: usshell
2 Replies

5. Solaris

Segmentation Fault (core dumped)

i am getting Segmentation Fault (core dumped) on solaris, but when i run the same program with same input on linux it runs successfully. How can i trace the fault in program on solaris. (6 Replies)
Discussion started by: junaid.nehvi
6 Replies

6. UNIX for Dummies Questions & Answers

Segmentaion Fault - Core dumped during cpio

The same cpio script has been working for years without modifications, until the last couple of nights when we get the error Segmentation Fault - core dumped and the cpio aborts. It appears to abort in relatively the same place every time and on multiple tapes. Do I have a bad tape drive,... (8 Replies)
Discussion started by: golfs4us
8 Replies

7. Solaris

segmentation fault core dumped

i am getting segmentation fault (core dumped) i tried following things but couldn't understand what is wrong with my prog and where the problem is.... i have only adb debugger available on solaris.... so plz help bash-3.00$ pstack core core 'core' of 765: ./mod_generalised_tapinread... (4 Replies)
Discussion started by: junaid.nehvi
4 Replies

8. Red Hat

Segmentation fault (core dumped)

Hi All, I am getting "Segmentation fault (core dumped)" error in the runtime. I am new this please can you tell me why is that i am getting this error and I am not sure of my compilation : gcc -c avc_test.c gcc -c md5.c gcc avc_test.o md5.o -shared -Llibcoreavc_sdk.so -o proj ... (1 Reply)
Discussion started by: fido.genial
1 Replies

9. Programming

Memory Fault (core dumped) in ttpy program

I´m writing this program in QNX , I`m kinda new to UNIX and programing in general, and when I try to run it it gives me the Memory Fault error. Can anyone help? #include <stdio.h> #include <fcntl.h> void main(void) {int a,ter; char buf; printf("a="); scanf("%d",a); ter=open... (6 Replies)
Discussion started by: GiganteAsesino
6 Replies

10. UNIX and Linux Applications

Tilda Segmentation fault (core dumped)

Can anyone tell me why I keep getting a Segmentation fault when I try to run tilda? $ tilda Segmentation fault (core dumped) It seemed to run after I deleted my tilda directory like this thread said to do. Unfortunately it wouldn't let me set my keybinding with anything I tried. ... (0 Replies)
Discussion started by: cokedude
0 Replies
PTHREAD_SETNAME_NP(3)					     Linux Programmer's Manual					     PTHREAD_SETNAME_NP(3)

NAME
pthread_setname_np, pthread_getname_np - set/get the name of a thread SYNOPSIS
#define _GNU_SOURCE /* See feature_test_macros(7) */ #include <pthread.h> int pthread_setname_np(pthread_t thread, const char *name); int pthread_getname_np(pthread_t thread, char *name, size_t len); Compile and link with -pthread. DESCRIPTION
By default, all the threads created using pthread_create() inherit the program name. The pthread_setname_np() function can be used to set a unique name for a thread, which can be useful for debugging multithreaded applications. The thread name is a meaningful C language string, whose length is restricted to 16 characters, including the terminating null byte (''). The thread argument specifies the thread whose name is to be changed; name specifies the new name. The pthread_getname_np() function can be used to retrieve the name of the thread. The thread argument specifies the thread whose name is to be retrieved. The buffer name is used to return the thread name; len specifies the number of bytes available in name. The buffer spec- ified by name should be at least 16 characters in length. The returned thread name in the output buffer will be null terminated. RETURN VALUE
On success, these functions return 0; on error, they return a nonzero error number. ERRORS
The pthread_setname_np() function can fail with the following error: ERANGE The length of the string specified pointed to by name exceeds the allowed limit. The pthread_getname_np() function can fail with the following error: ERANGE The buffer specified by name and len is too small to hold the thread name. If either of these functions fails to open /proc/self/task/[tid]/comm, then the call may fail with one of the errors described in open(2). VERSIONS
These functions first appeared in glibc in version 2.12. CONFORMING TO
These functions are nonstandard GNU extensions. NOTES
pthread_setname_np() internally writes to the thread-specific comm file under the /proc filesystem: /proc/self/task/[tid]/comm. pthread_getname_np() retrieves it from the same location. EXAMPLE
The program below demonstrates the use of pthread_setname_np() and pthread_getname_np(). The following shell session shows a sample run of the program: $ ./a.out Created a thread. Default name is: a.out The thread name after setting it is THREADFOO. ^Z # Suspend the program [1]+ Stopped ./a.out $ ps H -C a.out -o 'pid tid cmd comm' PID TID CMD COMMAND 5990 5990 ./a.out a.out 5990 5991 ./a.out THREADFOO $ cat /proc/5990/task/5990/comm a.out $ cat /proc/5990/task/5991/comm THREADFOO Program source #define _GNU_SOURCE #include <pthread.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> #define NAMELEN 16 #define errExitEN(en, msg) do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0) static void * threadfunc(void *parm) { sleep(5); // allow main program to set the thread name return NULL; } int main(int argc, char **argv) { pthread_t thread; int rc; char thread_name[NAMELEN]; rc = pthread_create(&thread, NULL, threadfunc, NULL); if (rc != 0) errExitEN(rc, "pthread_create"); rc = pthread_getname_np(thread, thread_name, NAMELEN); if (rc != 0) errExitEN(rc, "pthread_getname_np"); printf("Created a thread. Default name is: %s ", thread_name); rc = pthread_setname_np(thread, (argc > 1) ? argv[1] : "THREADFOO"); if (rc != 0) errExitEN(rc, "pthread_setname_np"); sleep(2); rc = pthread_getname_np(thread, thread_name, (argc > 2) ? atoi(argv[1]) : NAMELEN); if (rc != 0) errExitEN(rc, "pthread_getname_np"); printf("The thread name after setting it is %s. ", thread_name); rc = pthread_join(thread, NULL); if (rc != 0) errExitEN(rc, "pthread_join"); printf("Done "); exit(EXIT_SUCCESS); } SEE ALSO
prctl(2), pthread_create(3), pthreads(7) Linux 2014-05-28 PTHREAD_SETNAME_NP(3)
All times are GMT -4. The time now is 11:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy