Score:0

C program created many proccesses, crash the OS and stuffed 40GB into log directory

pl flag

I create the following program which needs to "play ping pong" between a parent process and its child process.

Even while working on it, while compiling, I noticed that my PC starts to work harder and harder but I didn't really think it's a problem.

In the end I found myself crashing my Linux, creating lots of different processes that slow down the PC and also create a lot temp/logs file and cause my disk to have 200MB of free space instead of 35GB .

How can I fix those problems?

  1. How can I stop my program from creating a lot of different processes?
  2. How can I clean up my logs directory? I tried sudo apt autoremove and autoclean and delete all .gz files in the /var/log directory.

But it did not help. My disk space still stands on free 200MB and a /var/log directory of almost 40GB for some reason.

I don't want to remove necessary files that located in the /var/log directory so I'm not removing the entire directory.

Why did my program even created so many temp or logs file?

Thanks.

is_parent_turn = 1;

void handle_siguser1(int signum);
void handle_siguser1(int signum);

int main()
{
    /*  create a child process  */
    pid_t pid = fork();
    
    if (pid < 0)
        exit(1);
    
    signal(SIGUSR1, handle_siguser1);
    signal(SIGUSR2, handle_siguser2);
    
    /*  returned to the newly created child process. */
    if (0 == pid)
    {   
        while (1)
        {
            /*  pause child process and let parent to begin */
            sleep(2);
            
            kill(getppid(), SIGUSR2);
            
        }
    }
        
    /* returned to parent */
    else
    {   
        while (1)
        {
            kill(getpid(), SIGUSR1);
        }
    }
        
    return 0;   
}
/******************************************************************************/
void handle_siguser1(int signum)
{
    if (is_parent_turn)
    {
        printf("\n\nPING\n\n");
        is_parent_turn = 0;
    }
    
    else
    {
        sleep(2);
    }
}
/******************************************************************************/
void handle_siguser2(int signum)
{
    if (!is_parent_turn)
    {
        printf("\n\nPONG\n\n");
        is_parent_turn = 1;
    }
    
    else
    {
        sleep(2);
    }
}

enter image description here

enter image description here

in flag
You may want to ask this question on StackOverflow, which is a development-centric site
NoobCoder avatar
pl flag
@matigo the major question here is "how should I clean up the `var/log` directory and remove all the files the were created by my program and take up more than 35GB without removing the really important system files
in flag
You can use the terminal or Nautilus get into the `/var/log/` directory and, from there, delete the large files. So long as you’re not removing directories or changing permissions, you’ll be fine …
NoobCoder avatar
pl flag
file called `syslog` is 22GB
Doug Smythies avatar
gn flag
and what are some of the entries in `/var/log/syslog`? The entries should help you debug your program.
Doug Smythies avatar
gn flag
Your c program seems incomplete, and does not compile as listed. I have made it compile, and it doesn't make any entries in `/var/log/syslog`, but it doesn't loop forever or terminate. It does print "PING" then "PONG" once. You should kill your stuff `killall a.out`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.