[slurm-users] run bash script in spank plugin

John Hearns hearnsj at googlemail.com
Mon Jun 4 07:30:05 MDT 2018


Tueur what are you trying to achieve here?  The example you give is
touch /tmp/newfile.txt'
I think you are trying to send a signal to another process. Could this be
'Hey - the job has finished and there is a new file for you to process'
If that is so, there may be better ways to do this. If you have a
post-processing step, then you can submit a job whihc depends on the main
job.
https://hpc.nih.gov/docs/job_dependencies.html

On 4 June 2018 at 15:20, Tueur Volvo <huitre39 at gmail.com> wrote:

> thanks for your answer, i try some solution but it's not work
>
> i try to add setsid and setpgrp for isolate my new process but slurm job
> sleep 6secondes and reboot my machine (i test with reboot command, but we
> can make other bash command, it's just example)
>
>         pid_t cpid; //process id's and process groups
>
>         cpid = fork();
>
>         if( cpid == 0 ){
>             setsid();
>             setpgrp();
>             execl("/bin/sh", "sh", "-c", "sleep 10; reboot1&", NULL);
>
>         }
>         wait(NULL);
>
>
> maybe i have a error in my code ?
>
> 2018-05-31 9:37 GMT+02:00 Yair Yarom <irush at cs.huji.ac.il>:
>
>> Hi,
>>
>> I'm not sure how slurm/spank handles child processes but this might be
>> intentional. So there might be some issues if this were to work.
>>
>> You can try instead of calling system(), to use fork() + exec(). If
>> that still doesn't work, try calling setsid() before the exec(). I can
>> think of situations where your process might still get killed, e.g. if
>> slurm (or even systemd) kills all subprocesses of the "job", by
>> looking at the cgroup. If that's the case, you'll need to move it to
>> another cgroup in addition/instead of setsid().
>>
>>     Yair.
>>
>>
>>
>> On Wed, May 30, 2018 at 5:16 PM, Tueur Volvo <huitre39 at gmail.com> wrote:
>> > Hello i have question, how run in background bash script in spank
>> plugin ?
>> >
>> > in my spank plugin in function : slurm_spank_task_init_privileged
>> >
>> > i want to run this script :
>> >
>> > system("nohup bash -c 'sleep 10 ; touch /tmp/newfile.txt' &");
>> >
>> > i want to run in independant process this bash script, i don't want
>> wait 10
>> > seconde in my slurm plugin
>> >
>> > i have this code :
>> > int slurm_spank_task_init_privileged (spank_t sp, int ac, char **av) {
>> >
>> > system("nohup bash -c 'sleep 10 ; touch /tmp/newfile.txt' &");
>> >
>> > return 0;
>> >
>> > }
>> >
>> > actualy it's not work, when slurm ending to run my job, he kill my nohup
>> > command
>> >
>> > if i  had in my c code sleep 12, my bash script work
>> >
>> >
>> > int slurm_spank_task_init_privileged (spank_t sp, int ac, char **av) {
>> >
>> > system("nohup bash -c 'sleep 10 ; touch /tmp/newfile.txt' &");
>> >
>> > sleep(12);
>> >
>> > return 0;
>> >
>> > }
>> >
>> > but i don't want to wait, i want to run my bash script in independant
>> > process
>> >
>> > thanks for advance for your help
>> >
>> >
>> >
>> >
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schedmd.com/pipermail/slurm-users/attachments/20180604/61649010/attachment.html>


More information about the slurm-users mailing list