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?
- How can I stop my program from creating a lot of different processes?
- 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);
}
}