Unable to kill processes running concurrently

user3033194

I am running a program A.c concurrently, say 5 times. A part of the code is given below:

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

    char s = 0;
    int i = 0;
    pid_t procB_id = 0;
    int retval = 0;

    struct sigaction act;
    ch = &c[0];
    memset(c, 0, 50);

    // open the file entered in the command-line for reading 
    fptr = fopen(argv[1], "r");

    if(fptr == NULL){
            printf("Error - input file could not be opened for reading!\n");
        exit(EXIT_FAILURE);
        }

    // Write characters read by file pointer to an array
    while((s=fgetc(fptr)) != EOF){
        ch[i] = s;
        i++;
    }
    printf("Length of text: %d\n",i);

    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_SIGINFO;
    act.sa_sigaction = handlerA;

    if((sigaction(SIGRTMIN, &act, NULL)) != 0){
        printf("Signal could not be registered!\n");    
    }

    //get PID of daemon B to be able to send it a real-time signal, indicating that A has started
    procB_id = getBprocessID();

    printf("PROCESS ID OF B: %d\n", (int) procB_id);

    //call sendSignal() method to send real-time signal to B
    retval = sendBSignal(procB_id);

    if(retval == 1){

        while(n < 0){
            //printf("BEFORE PAUSE\n");
            pause();
        }
        //writeToFIFO(n);
        if(writeToFIFO(n) == 1){
            n = -1;
            exit(EXIT_SUCCESS);
        }
    }


    while (1);
}

The relevant part of the code is really exit(EXIT_SUCCESS). However, when I am running the process A in parallel, only 1 process is exiting, not the rest. The others are still running. I am running the process in parallel by the following shell script:

for ((i=1;i<=5;i++))

do

    ./A file.txt &
done

"file.txt" is a file each process has to read separately. I want to kill all 5 processes, not just one. Does anyone know how I can do that? Please help. I guess my code is not correct, but I don't know what to do here.

Maxim Egorushkin

I want to kill all 5 processes, not just one. Does anyone know how I can do that?

pkill -f "A file.txt"

You probably lost a do loop for your infinite while(1):

do {
    procB_id = getBprocessID();

    printf("PROCESS ID OF B: %d\n", (int) procB_id);

    //call sendSignal() method to send real-time signal to B
    retval = sendBSignal(procB_id);

    if(retval == 1){
        while(n < 0){
            //printf("BEFORE PAUSE\n");
            pause();
        }
        //writeToFIFO(n);
        if(writeToFIFO(n) == 1){
            n = -1;
            exit(EXIT_SUCCESS);
        }
    }
} while (1);

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Check if process is running and kill it

分類Dev

How do I kill processes in Ubuntu?

分類Dev

Webserver compromised, strange processes running

分類Dev

when parent process is killed by 'kill -9', how to terminate child processes

分類Dev

C++ application does not kill all processes on exit

分類Dev

How do I kill all processes except PID 1?

分類Dev

CentOS - killall command (to kill all processes with names matching a given pattern)

分類Dev

How to kill all processes owned by `user` on Centos 7?

分類Dev

How to kill a running process using ansible?

分類Dev

How can I see what processes are running?

分類Dev

POSIX semaphore with related processes running threads

分類Dev

How to clean foreverjs logs for running processes?

分類Dev

2 of the same processes with different PIDs running - not threaded

分類Dev

How to set the precise max number of concurrently running tasks per node in Hadoop 2.4.0 on Elastic MapReduce

分類Dev

bash shutdown hook; or, kill all background processes when main process is killed

分類Dev

How to kill VueJS application running on localhost:8080 (MacOS)

分類Dev

VPN kill switch when running on Hyper-V

分類Dev

How can I fully kill a program and/or python code running on Windows?

分類Dev

Understanding ps elapsed time format for long running processes

分類Dev

setting (system-wide) CPU affinities for running processes on a Linux platform

分類Dev

Running a single executable with sudo adds two processes in process list

分類Dev

Spark Kill Runningアプリケーション

分類Dev

Error in SLURM cluster - Detected 1 oom-kill event(s): how to improve running jobs

分類Dev

Does Android have some functionality that kills all running processes and requires a reboot to fix?

分類Dev

Linux Apache Server Running Phusion Passenger and 2 Apps has 8 ruby processes?

分類Dev

How can I get a list of long running processes that match a particular pattern?

分類Dev

Best practice for load balanced Web API that uses shared long running processes?

分類Dev

Powershell how to get a list of running processes and run them through the MD5 algorithm

分類Dev

jmh: Run benchmark concurrently

Related 関連記事

  1. 1

    Check if process is running and kill it

  2. 2

    How do I kill processes in Ubuntu?

  3. 3

    Webserver compromised, strange processes running

  4. 4

    when parent process is killed by 'kill -9', how to terminate child processes

  5. 5

    C++ application does not kill all processes on exit

  6. 6

    How do I kill all processes except PID 1?

  7. 7

    CentOS - killall command (to kill all processes with names matching a given pattern)

  8. 8

    How to kill all processes owned by `user` on Centos 7?

  9. 9

    How to kill a running process using ansible?

  10. 10

    How can I see what processes are running?

  11. 11

    POSIX semaphore with related processes running threads

  12. 12

    How to clean foreverjs logs for running processes?

  13. 13

    2 of the same processes with different PIDs running - not threaded

  14. 14

    How to set the precise max number of concurrently running tasks per node in Hadoop 2.4.0 on Elastic MapReduce

  15. 15

    bash shutdown hook; or, kill all background processes when main process is killed

  16. 16

    How to kill VueJS application running on localhost:8080 (MacOS)

  17. 17

    VPN kill switch when running on Hyper-V

  18. 18

    How can I fully kill a program and/or python code running on Windows?

  19. 19

    Understanding ps elapsed time format for long running processes

  20. 20

    setting (system-wide) CPU affinities for running processes on a Linux platform

  21. 21

    Running a single executable with sudo adds two processes in process list

  22. 22

    Spark Kill Runningアプリケーション

  23. 23

    Error in SLURM cluster - Detected 1 oom-kill event(s): how to improve running jobs

  24. 24

    Does Android have some functionality that kills all running processes and requires a reboot to fix?

  25. 25

    Linux Apache Server Running Phusion Passenger and 2 Apps has 8 ruby processes?

  26. 26

    How can I get a list of long running processes that match a particular pattern?

  27. 27

    Best practice for load balanced Web API that uses shared long running processes?

  28. 28

    Powershell how to get a list of running processes and run them through the MD5 algorithm

  29. 29

    jmh: Run benchmark concurrently

ホットタグ

アーカイブ