0

I am fairly new to Ubuntu, so I apologize for any bad questions.

I am making a C program that syncs multiple folders to remote destinations. I am planning to invoke this script from the C program: Automatic synchronization via rsync.

The script only works for 1 directory, so I will have to have many instances to cover each directory. Therefore, I want to run the scripts in the background instead of terminals popping up everywhere.

Then there's also the problem of how do I kill all the background scripts that are endlessly looping when user decides to stop synchronization.

Thanks in advance!

Community
  • 1
  • 1
Murdock L
  • 3
  • 2

2 Answers2

0

You could try to use pkill or killall first :

$ pkill <script name>
# or ...
$ killall <script name>

If you want to force the kill of your process list :

$ ps -ef|awk '($0 ~ "<processname>"){print $2}'|while read -r; do kill -9 $REPLY; done

The column number of the PID (2 in my example) may change, depending on the OS.

Idriss Neumann
  • 3,760
  • 2
  • 23
  • 32
0

I think your question is "how do you kill processes from C?" If so, the answer is to use the kill() function. You can send any signal, but SIG_KILL is the default used by the command line version of kill.

abligh
  • 24,573
  • 4
  • 47
  • 84