Drkcore

09 09 2009 OCaml Tweet

OCamlでfork

どう書くの外部の実行ファイルを呼び出しって問題を解く。

ブロックする版は

#load "unix.cma";;
Unix.system "/bin/sleep 3";;
print_string "waited\n";;

でいいんでしょ。

で、ブロックしない版をこんな感じで書いたら、

let pid = Unix.fork () in match pid with
     0 -> Unix.system "/bin/sleep 3"; print_string "waited\n"
   | _ -> print_string "not wait\n"
;;

warningがでる。

Warning S: this expression should have type unit.

よくわからなくて気持ち悪い。

追記090909

ignoreを使えばよいとはてブで教えてもらった。

# ignore;;
- : 'a -> unit = <fun>

unitを返す

let pid = Unix.fork () in match pid with
     0 -> ignore(Unix.system "/bin/sleep 3"); print_string "waited\n"
   | _ -> print_string "not wait\n"
;;

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021